不使用SMTP的PHPmailer [英] PHPmailer without using SMTP
问题描述
我已经将PHPMailer文件夹添加到Web服务器上的根文件夹中,但是我只收到与SMTP有关的错误.
I've added the PHPMailer folder to my root folder on my web server and I just get an error that has to do with SMTP.
是否有一种无需登录邮件帐户即可使用PHPMailer的方法? 我可以让服务器将电子邮件发送到一个地址吗?
Is there a way to use PHPMailer without needing to log into a mail account? Can I just have the server send the email to a address?
我正在搜索该站点并找到了
I was searching this site and found this
$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();
但是我收到一条错误消息,提示"Message could not be sent.Mailer Error: You must provide at least one recipient email address."
But I get an error that says "Message could not be sent.Mailer Error: You must provide at least one recipient email address."
推荐答案
我注释掉了SMTP行,现在可以了
I commented out the SMTP lines and now it works
<?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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!