![](/img/trans.png)
[英]WAMP / Drupal 7 / SMTP module : Can't send mail with drupal_mail, but “testing mail” can send
[英]can't send mail through SMTP
由于某些原因,我无法通过免费的虚拟主机发送电子邮件。 网络托管服务说SMTP已启用,但是当我单击“发送”按钮时,它将仅将我重定向到白色空白页。 没有错误代码,仅是一个白页。 告诉我代码有什么问题吗? 建议将不胜感激。
PS- 所需的输入也不起作用,当我在每个字段为空的情况下按发送按钮时,仍然会打开send.php ...
我的HTML表单:
<form action="send.php" method="POST">
<div class="cdiv">
<input name="name" class="info" type="text" placeholder="Enter Name" required />
</div>
<div class="cdiv">
<input name="email" class="info" type="email" placeholder="Enter Your Email ID" required />
</div>
<div class="cdiv" style="height:75px;">
<textarea name="message" class="info" rows="3" placeholder="Enter Your Message" required></textarea>
</div>
<button type="submit" id="sendbtn">SEND</button>
</form>
我的send.php:
<?php
$body = $_POST['message'];
$subject = 'Automated message';
$from = $_POST['email'];
$from_name = $_POST['name'];
require_once("class.phpmailer.php");
require_once("class.smtp.php");
require_once("class.pop3.php");
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "dhruv1103@gmail.com";
$mail->Password = "password";
$mail->SetFrom = $from;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress = "dhruv1103@gmail.com";
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
echo "Sent!";
return true;
}
?>
加入之后
require_once("class.phpmailer.php");
这个
require_once 'class.smtp.php';
require_once 'class.pop3.php';
那么你可以替换这行
$mail->SetFrom = $from;
这样
$mail->From = $from;
$mail->FromName = $from_name;
告诉我你得到什么?
我又得到一张空白页...
以此替换send.php(不要忘记密码)
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'dhruv1103@gmail.com';
$mail->Password = 'Your password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//$mail->SMTPDebug = 2;
$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->addAddress('dhruv1103@gmail.com');
$mail->WordWrap = 50;
$mail->Priority = 1;
$mail->isHTML(true);
$mail->Subject = 'Automated message';
$mail->Body = $_POST['message'];
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->CharSet = 'UTF-8';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.