我已将 PHPMailer 文件夹添加到我的网络服务器上的根文件夹中,但我只是收到一个与 SMTP 有关的错误。
有没有无需登录邮件帐户即可使用 PHPMailer 的方法? 我可以让服务器将电子邮件发送到一个地址吗?
我正在搜索这个网站并找到了这个
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );
$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';
$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );
return $email->Send();
但我收到一条错误消息,提示 “无法发送邮件。邮件错误:您必须至少提供一个收件人电子邮件地址。”
最佳答案
我注释掉了 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 = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('name@domain.com', 'User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$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/