使用phpmailer发送邮件无法正常工作

时间:2016-12-23 11:43:23

标签: php phpmailer

我正在尝试使用带有位于服务器上的pdf附件的phpmailer从php发送邮件。我的代码如下。我不确定我哪里出错了。请帮我。提前致谢

require_once('class.phpmailer.php');

$bodytext = "Test mail";
$email = new PHPMailer();
$email->From      = 'myid@something.com';
$email->FromName  = 'my name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'something@gmail.com' );

$file_to_attach = 'pdffiles/test.pdf';

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

$email->Send();

1 个答案:

答案 0 :(得分:1)

我认为当您发送文件时,您需要提供系统路径而不是网址路径

$bodytext = "Test mail";
$email = new PHPMailer();
$email->From      = 'myid@something.com';
$email->FromName  = 'my name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'something@gmail.com' );

$file_to_attach = SYSTEM_PATH.'pdffiles/test.pdf';

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

$email->Send();