PHP Send HTML mail

前端 未结 3 630
情话喂你
情话喂你 2021-01-26 21:46

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
    $to  = \'mail\';

             


        
3条回答
  •  暖寄归人
    2021-01-26 22:33

    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.

提交回复
热议问题