Page 1 of 1

Php mailer function Question

Posted: Thu Jan 14, 2010 10:02 am
by Rokoshiru
Hey guys,

I've been coding in php for a while now and typically I havent had too many problems with it but currently I am working on a mailer function for a site and I'm up against a wall and I wanted to see if anyone else could help me with this:

I am sending an HTML email to the user after they've answered a few questions, however, when they try to open the email they see all the html tags in it and even though I have the headers set up to send in html. Here is my code:

Code: Select all

 
        $emailRecipient = $_POST["email"];
    $messageBody = "<html><head></head><body>" . $contactDetails . "<br />" . $benefitsDetails . "</body></html>";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    if (mail($emailRecipient,"American Legion Benefits Summary",$messageBody,"From:American Legion",$headers))
    {
        echo "Email Successful!";
    }
    else
    {
        echo "Error!";
    }
 
Can someone point me in the right direction and let me know where I am going wrong? Thank you!

Re: Php mailer function Question

Posted: Thu Jan 14, 2010 10:44 am
by Charles256
Give http://swiftmailer.org/ a try. Thousands of man hours have been spent building what you're trying to do so it'll probably help you out. Of course you're welcome to diagnose you're problem and it'll probably help you in the long run to fully understand but if you're in a hurry the site I linked you to will help tremendously.

Re: Php mailer function Question

Posted: Thu Jan 14, 2010 12:15 pm
by SimpleManWeb
I believe the issue is with your "mail" line. You don't hand in the "headers" variable in the right order:

Try changing this:

Code: Select all

 
    if (mail($emailRecipient,"American Legion Benefits Summary",$messageBody,"From:American Legion",$headers))
 


To This:

Code: Select all

 
     if (mail($emailRecipient,"American Legion Benefits Summary",$messageBody,$headers))
 
You can add your "From" information to the headers like this:

Code: Select all

 
     $headers = "From: American Legion <noreply@americanlegion.com>" . chr(13) . chr(10)
     . "MIME-Version: 1.0" . chr(13) . chr(10)
     . "Content-type: text/html; charset=iso-8859-1";
 
 
Hope This Helps

Re: Php mailer function Question

Posted: Thu Jan 14, 2010 1:33 pm
by Rokoshiru
SimpleManWeb wrote:I believe the issue is with your "mail" line. You don't hand in the "headers" variable in the right order:

Try changing this:

Code: Select all

 
    if (mail($emailRecipient,"American Legion Benefits Summary",$messageBody,"From:American Legion",$headers))
 


To This:

Code: Select all

 
     if (mail($emailRecipient,"American Legion Benefits Summary",$messageBody,$headers))
 
You can add your "From" information to the headers like this:

Code: Select all

 
     $headers = "From: American Legion <noreply@americanlegion.com>" . chr(13) . chr(10)
     . "MIME-Version: 1.0" . chr(13) . chr(10)
     . "Content-type: text/html; charset=iso-8859-1";
 
 
Hope This Helps
Thanks buddy! That fixed it! I've been SO frustrated with this. Thanks again!!!!!