Send attachments with PHP Mail()?

前端 未结 14 2509
北恋
北恋 2020-11-21 04:46

I need to send a pdf with mail, is it possible?

$to = \"xxx\";
$subject = \"Subject\" ;
$message = \'Example message with html\';
$header         


        
14条回答
  •  自闭症患者
    2020-11-21 05:08

    100% working Concept to send email with attachment in php :

    if (isset($_POST['submit'])) {
      extract($_POST);
      require_once('mail/class.phpmailer.php');
    
      $subject = "$name Applied For - $position";
      $email_message = "
    Thanks for Applying ....
    "; $mail = new PHPMailer; $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "mail.companyname.com"; // SMTP server $mail->SMTPDebug = 0; $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "info@companyname.com"; // GMAIL username $mail->Password = "mailPassword"; // GMAIL password $mail->SetFrom('info@companyname.com', 'new application submitted'); $mail->AddReplyTo("name@yourdomain.com","First Last"); $mail->Subject = "your subject"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($email_message); $address = 'info@companyname.com'; $mail->AddAddress($address, "companyname"); $mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']); // attachment if (!$mail->Send()) { /* Error */ echo 'Message not Sent! Email at info@companyname.com'; } else { /* Success */ echo 'Sent Successfully! Check your Mail'; } }

    I used this code for google smtp mail sending with Attachment....

    Note: Download PHPMailer Library from here -> https://github.com/PHPMailer/PHPMailer

提交回复
热议问题