我对php很新,我想用php邮件发送电子邮件。 y代码给我一个成功的消息,但电子邮件没有交付。 这是我的代码。
<?php
use phpmailer\phpmailer\PHPMailer;
use phpmailer\phpmailer\SMTP;
use phpmailer\phpmailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "mail@gmail.com";
$mail->FromName = "Elvis ";
//To address and name
$mail->addAddress("mail1@gmail.com", "Elvis");
$mail->addAddress("mail2@gmail.com"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("mail1@gmail.com", "Reply");
//CC and BCC
//$mail->addCC("cc@example.com");
//$mail->addBCC("bcc@example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
我首先使用composer安装了phpmailer但是我给了我一个错误 PHP致命错误:未捕获错误:类&#39; PHPMailer&#39;在日志上,所以我手动包含文件。
答案 0 :(得分:0)
您使用默认的mail()
传输进行发送,这意味着邮件是通过您的本地邮件服务器发送的,因此请查看其日志,通常是/var/log/mail.log
之类的内容,这会告诉您发生了什么提交后的消息。