PHP Send HTML mail
I am trying to send an HTML mail through PHP, but I can't seem to get it working.
This is my code:
    // multiple recipients
开发者_如何学C    $to  = 'mail';
    // subject
    $subject = 'Subject';
    // message
    $message = "
    <html>
    <head>
      <title>Thanks</title>
    </head>
    <body>
        <div>
            <b>Thanks for your email</b>
        </div>
    </body>
    </html>
    ";
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    // Additional headers
    $headers .= 'To: info <info@example.com>' . "\r\n";
    $headers .= 'From: Pynix <info@example.com>' . "\r\n";
    // Mail it
    mail($to, $subject, $message, $headers);
This also doesn't show any sender when I receive it in Outlook.
Anyone an idea?
Thanks
I don't think you have to put the To: line in the header as it is a parameter of the mail function.
However some mail clients don't like light headers, here's mine which is working:
$header = 'From: "Contact" <mail>'.PHP_EOL.
                  'Reply-to: <mail>'.PHP_EOL.
                  'MIME-Version: 1.0'.PHP_EOL.
                  'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
                  'Content-Transfer-Encoding: 8bit'.PHP_EOL.
                  'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
I use SwiftMailer:
require_once('../lib/swiftMailer/lib/swift_required.php');
...
function sendEmail(){
  //Sendmail
  $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
  //Create the Mailer using your created Transport
  $mailer = Swift_Mailer::newInstance($transport);
  $body="Dear $fname,\n\nYour job application was successful. \n\nYours,\n\nEamorr\n\n\n\n\n\n\n";
  //Create a message
  $message = Swift_Message::newInstance('Subject goes here')
    ->setFrom(array($email => "no-reply@yourdomain.com"))
    ->setTo(array($email => "$fname $lname"))
    ->setBody($body);
  //Send the message
  $result = $mailer->send($message);
}
You can send both plaintext and html email with ease.
Fixed.
I found this which for some reason worked perfectly on my server:
// Set The Headers:
$headers        =   'From: "Me" <info@skillsexchangenetwork.net>'.PHP_EOL.
'Reply-to: <Me@Him.com>'.PHP_EOL.
'Cc: <Her @There.com>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-type: text/html; charset=iso-8859-1'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
// Send:
mail($to, $subject, $message, $headers);
Thanks for the input guys.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论