我正在使用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;
}
请指导我这个..
答案 0 :(得分:0)
你使用了变量$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;
}