This little code is working fine with PHP4 but not sending with PHP5. What should I do to make it work with PHP5? <?php $FirstName=$_POST['FirstName']; $LastName=$_POST['LastName']; $Email=$_POST['Email']; $Phone=$_POST['Phone']; $sujet2="$FirstName $LastName asked for it!"; $message2="Hi Cody ,\n\n"; $message2.="My first name is $FirstName.\n"; $message2.="My last name is $LastName.\n"; $message2.="My email is $Email\n"; $message2.="My phone is $Phone\n"; $headers2="From: $FirstName $LastName<$Email>\n"; mail("cody@cody.com",$sujet2,$message2,$headers2); ?> PHP:
The code is fine, what I think is no longer good are the sendmail settings on your server. Also, it would be good to know what problem do you have: the mail is not sent or the mail is sent but not received. In case you do not receive it there might be a spam filter that rejects the email because of incomplete headers.
I have replaced my original code by this: <?php require_once "Mail.php"; $to = "$FirstName $LastName <$Email>"; $from = " Cody <cody@cody.com>"; $subject = " Hello $FirstName $LastName"; $body = " Hi Cody ,\n\n My first name is $FirstName.\n My last name is $LastName.\n My email is $Email\n My phone is $Phone\n "; $host = localhost $username = your_cpanel_username $password = your_cpanel_password $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> PHP: And installing the PEAR Mail package Now, I'm still trying to figure out my HTML. The Content-type doesn't do any good so far.
I've had the same problem, I use http://phpmailer.sourceforge.net. This is a great script. I really don't use all the functionality, but it allows attachments, multiple addresses, bcc, cc, blah blah blah. A nice feature I use is the html setting to send html mails. Like I said, I only use the basics, so if you want more info you'll have to go look John