Forum Moderators: coopster
I was hoping someone could help me. I have a client who needs the following:
1) end user fills out form online with name, email address
2) end user clicks "submit" button
3) form processes automatically:
a) end user's information gets passed via e-mail to my client
b) based on information the end user entered in the form, and automatic email is generated *back* to the end user, with a link.
Now, I had this working before, and tested it on two different servers, and it was a beautiful thing. But this was *before* I discovered that 1) the client had a Windows server and 2) they didn't have PHP installed.
They've finally gotten around to installing PHP5 (and unfortunately, the script was written for PHP4) and now it's all screwed up.
I spent the last week figuring out how to get mail sent *at all* - and finally did so, using PHPMailer. I can get most of my other forms to work fine, but this one is just proving to be a headache.
The problem is that, in the old form that worked, I basically just had 2 settings, like so:
$today = date("F j, Y");
$name = $firstname $lastname;
// Message to company from end user
$mailheader = "From: $name <$email>\nContent-Type: text/html";
$message = "Name: $name<br>";
$message.= "Company: $company<br>";
$message.= "Phone: $phone<br>";
$message.= "e-Mail address: $email";
//Message to end user from the company with link
$mailheader2= "From Company <company@email.com>\nContent-Type: text/html; charset=iso-8859-15";
$message2 = "From: Company<br>";
$message2.= "To: $name ($email)<br>";
$message2.= "Date: $today<br>";
$message2.= "Subject: White Paper Request<br><br>";
$message2.= "Thank-you for your interest. As you requested, please find our FREE white paper entitled \"Detecting Requirements Errors\" by <a href=\"http://www.companyurlhere.com/pdfs/n8_whitepaper.pdf\">clicking here</a>.<br><br>";
$message2.= "Please don't hesitate to contact us if you have any questions or if you need more information.<br><br>";
mail($to, $subject, $message, $mailheader);
mail("$name <$email>","Your Requested White Paper","$message2","$mailheader2");
Now *that* worked fine, before. But their server was set up so that if you were sending an e-mail from a domain that *wasn't* the company's, it would puke up an error. Something about open relays or something.
Anyway, PHPMailer was the only thing I found (thanks to this board!) that would set it up so I could authenticate the e-mails sent and allow other domains to send e-mails and info. But now I've discovered that PHPMailer won't allow me to do as above - just add a "2" to the secondary section and send both emails. If I do that, the page goes blank and nothing works. If I try to add secondary items to the same as the first, they override the first email, and only the second is sent (end user gets his link, but the client gets nothing)
I need to find a way - and QUICKLY, as this project os about 2 weeks overdue - to get PHPMailer working with what I've got above.
The PHPMailer script I've got now (that works) is below (just the necessary section) - the secondary email area is currently commented out.
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
$mail = new FreakMailer();
$mail->From = "Company";
$mail->FromName = "company@email.com";
$body = "Name: $name<br>";
$body.= "Company: $company<br>";
$body.= "Phone: $phone<br>";
$body.= "e-Mail address: $email<br>";
$mail->ContentType = "text/html";
$mail->Subject = "Customer Information Regarding a Requested White Paper";
$mail->Body = $body;
$mail->AddAddress('me@myemail.com', 'Shelly');
$mail->Send();
//$mail = new FreakMailer();
//$mail->From = "$email";
//$mail->FromName = "$name";
//
//$body = "From: Company Name<br>";
//$body.= "To: $name ($email)<br>";
//$body.= "Date: $today<br>";
//$body.= "Subject: White Paper Request<br><br>";
//$body.= "Thank-you for your interest. As you requested, please find our FREE white paper entitled \"Detecting Requirements Errors\" by <a href=\"http://www.companyurlhere.com/pdfs/n8_whitepaper.pdf\">clicking here</a>.<br><br>";
//$body.= "Please don't hesitate to contact us if you have any questions or if you need more information.<br><br>";
//
//$mail->ContentType = "text/html; charset=iso-8859-15";
//$mail->Subject = "Your Requested White Paper";
//$mail->Body = $body;
//$mail->AddAddress('me@myemail.com', 'Shelly');
//$mail->Send();
I realize that the second just basically copies the first at the moment (and that would *definitely* override things) - but I've tried everything else and I just set it for "prettiness purposes" to try and keep my head wrapped around it. Believe me, I've tried other stuff. I *know* there's a way to do this...would it require sessions? an "if then" thatement? I just can't figure it out. Even if, somehow, I could have the thank you page that pops up send an email to the end user automatically, that would probably work.
If anyone could help me, I'd *so* appreciate it. I'm desperate for assistance!
Thanks!
## SEND MAIL TO VISITOR, IF THEY INCLUDED EMAIL if ($email) { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "mail.example.com"; $mail->SMTPAuth = true; $mail->Username = $phpuname; $mail->Password = $phppassw; $mail->SetLanguage("en","/usr/local/apache/phpmailer/language/"); $mail->From = "user@example.com"; $mail->FromName = "Example.com"; $mail->AddAddress($email,$uname); $mail->AddReplyTo("user@example.com","Example.com"); $mail->Subject = $subjectto; $mail->Body = $tomail; if(!$mail->Send()) { echo "Message was not sent <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }}} ## SEND MAIL TO ADMIN $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "mail.example.com"; $mail->SMTPAuth = true; $mail->Username = $phpuname; $mail->Password = $phppassw; $mail->SetLanguage("en","/usr/local/apache/phpmailer/language/"); $mail->From = "user@example.com"; $mail->FromName = "User"; $mail->AddAddress("user@example.com","Form Submitted"); $mail->AddAddress("me@example.com","My Name"); ## JUST IN CASE THE USER DIDN'T INCLUDE AN EMAIL ADDRESS ## if (!$email) { $email="user@example.com"; $tuname="NO REPLY"; $mail->AddReplyTo($email,$tuname); } ## IF THEY DID, MAKE REPLY-TO GO BACK TO THEM ## else { $mail->AddReplyTo($email,$uname); } $mail->Subject = $subjectus; $mail->Body = $usmail; if(!$mail->Send()) { echo "Message was not sent <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }