我已将PHPMailer文件夹添加到Web服务器上的根文件夹中,而我刚收到一个与SMTP有关的错误。
有没有一种方法可以使用PHPMailer而不需要登录邮件帐户?
我可以让服务器将电子邮件发送到一个地址吗?
我正在搜索该网站并找到了这个
$email = new PHPMailer();
$email->From = '[email protected]';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( '[email protected]' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
但我收到一个错误,说
"Message could not be sent.Mailer Error: You must provide at least one recipient email address."
最佳答案
我注释掉了SMTP行,现在可以正常工作了
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
//$mail->isSMTP(); // Set mailer to use SMTP
//$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = ''; // SMTP username
//$mail->Password = ''; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$mail->addAttachment(''); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
关于不使用SMTP的PHPmailer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32427920/