这是我发送电子邮件的PHP代码。我得到按摩'邮件被发送,你可以发送另一个'但电子邮件不发送。
Dockerfile
我使用Cpanel来托管我的网站。这有什么特殊配置吗?我是php的新手。请帮帮我。
答案 0 :(得分:1)
邮件功能不提供身份验证功能。您必须使用Mail Pear包中的Mail类。请看这里的例子:
答案 1 :(得分:0)
我假设你是基于你使用Cpanel的事实共享主机,一些共享主机解决方案不能很好地使用php的mail()函数,我发现使用phpmailer { {3}}效果更好,功能更多
使用phpmailer: 从链接下载,将文件放在您的Web应用程序可访问的文件夹中。
代码:
$email_from = $_POST['email'];
$email_from = "from@gmail.com"; // this overwrites the $_POST['email'] value, check this
$email_from_name = "Nishanthi";
$gmailUsername = "from@gmail.com";
$gmailPassword = "mysecretpassword";
$mail_to_send_to = "to@gmail.com";
$your_feedbackmail = "from@gmail.com";
$emailSubject = "Place Subject Here";
$emailContent = "This message can contain <b>HTML</b>";
require '[path_to_your_phpmailer_files]/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2; //Enable SMTP debugging
$mail->Debugoutput = 'html'; //Ask for HTML-friendly debug output
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $gmailUsername; // SMTP username
$mail->Password = $gmailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($email_from, $email_from_name);
$mail->addAddress($mail_to_send_to);
$mail->addReplyTo($your_feedbackmail);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $emailSubject;
$mail->Body = $emailContent;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message was sent, you can send another one';
}
?>