php mailer attachments

后端 未结 3 2056
小蘑菇
小蘑菇 2020-12-21 20:18

I have been using this script to send emails to certain staff but because of changes to my system i have to now send attachements with the email and i have tried multipul pe

3条回答
  •  滥情空心
    2020-12-21 20:38

    Your code looks fairly straightforward and syntactically correct. Is the script returning any error messages?

    If you're receiving the message without any issues, then the problem doesn't look to be in your code.

    A few things to check:

    • Make sure that the file "matt.txt" is both readable by your webserver and that the path is correct. The path to the file needs to be included in the $mail->AddAttachment() method call and should be relative to the script's location.
    • Verify that your mail server isn't stripping any attachments out due to restrictions and/or try sending a different attachment file type (try a .zip or a .jpg file)
    • If you're running a newer version of phpMailer, you can try catching any exceptions that are thrown (perhaps one that isn't preventing the message from going out, but just preventing the attachment from being included) using the following syntax: (taken from phpMailer Example Code)

      require 'PHPMailer/PHPMailerAutoload.php';
      $mail = new PHPMailer(true);
      try {
      
        $mail->IsSMTP();    // set mailer to use SMTP
        $mail->Host = "SMTP.SErver.com";    
      
        $mail->From = "From@email.com";    
        $mail->FromName = "HCSC";  
        $mail->AddAddress("To@email.com", "Example"); 
        $mail->AddReplyTo("Reply@email.com", "Hcsc"); 
      
        $mail->WordWrap = 50;    
        $mail->IsHTML(false);    
      
        $mail->Subject = "AuthSMTP Test";
        $mail->Body    = "AuthSMTP Test Message!";
        $mail->AddAttachment("matt.txt");
        echo "Message Sent OK

      \n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! }

提交回复
热议问题