![](/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.