【问题标题】:PHP mailer attachment email not working [duplicate]PHP邮件附件电子邮件不起作用[重复]
【发布时间】:2015-12-29 04:53:00
【问题描述】:

我正在使用 phpmailer 并尝试发送带有附件的电子邮件,但电子邮件不起作用(不发送电子邮件)以及附件。

require_once 'phpmailer/class.phpmailer.php';
if (isset($_REQUEST['FindDealer'])) {
    $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message,
    $mail->MsgHTML(file_get_contents('contents . html'));
    $email->AddAttachment( $file_to_attach , 'pdf . pdf);
    return $email->Send();
    exit;
}

请指导我这个..

【问题讨论】:

标签: php email phpmailer


【解决方案1】:

你在每一行都使用了变量$mail,除了这些行:

$email->AddAttachment( $file_to_attach , 'pdf . pdf);
return $email->Send();

将它们更改为以下内容,它应该可以工作:

$mail->AddAttachment( $file_to_attach , 'pdf . pdf);
return $mail->Send();

编辑:并修复错误(请参阅语法突出显示):

require_once 'phpmailer/class.phpmailer.php';
if (isset($_REQUEST['FindDealer'])) {
    $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    $mail->AddReplyTo('name@yourdomain.com', 'First Last');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message, ';
    $mail->MsgHTML(file_get_contents('contents . html'));
    $mail->AddAttachment( $file_to_attach , 'pdf . pdf');
    return $mail->Send();
    exit;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 2016-07-15
    • 2014-05-01
    相关资源
    最近更新 更多