[英]i am unable to send mail with help oh PHPMailer in yii 2.0
每當我單擊發送按鈕時,它總是會觸發0值(其他部分)。每當我單擊發送按鈕時,它總是會觸發0值(其他部分)。我無法在Yii 2.0框架中借助PHPMailer在服務器上發送郵件。 。我無法在Yii 2.0框架中借助PHPMailer在服務器上發送郵件。 請幫助我,謝謝你!
<?php
//Check e-mail validation
function check_email($email){
if(!@eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
return false;
} else {
return true;
}
}
function validate_mobile($mobile)
{
return preg_match('/^[0-9]{10}+$/', $mobile);
}
//Get post data
if(isset($_POST['name']) and isset($_POST['email']) and isset($_POST['mobile'])){
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$comment = $_POST['comment'];
if($name == '') {
echo json_encode(array('info' => 'error', 'msg' => "Please enter your name."));
exit();
} else if($email == '' or check_email($email) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter valid e-mail."));
exit();
} else if($mobile == '' or validate_mobile($mobile) == false){
echo json_encode(array('info' => 'error', 'msg' => "Please enter 10 digit mobile number."));
exit();
} else if($comment == ''){
echo json_encode(array('info' => 'error', 'msg' => "Please enter your message."));
exit();
} else {
$message = '
<html>
<head>
<title>Mail from '. $name .'</title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="tableContent bgBody" align="center" style="font-family:Helvetica, sans-serif; width:100%;">
<tr>
<td style="padding-bottom: 28px;">
<table style="font-size:14px;width:100%;">
<tr>
<td style="width:18%;">
<b>Name :</b>
</td>
<td>
<span style="">
'.$name.'
</span>
</td>
</tr>
<tr>
<td style="width:18%;">
<b>Email :</b>
</td>
<td>
<span style="">
'.$email.'
</span>
</td>
</tr>
<tr>
<td>
<b>Contact Number :</b>
</td>
<td>
<span style="">
'.$mobile.'
</span>
</td>
</tr>
<tr>
<td>
<b>Message :</b>
</td>
<td>
<span style="">
'.$comment.'
</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
require 'PHPMailer/PHPMailerAutoload.php';
//Send Mail
$mail->addReplyTo = "user@gmail.com";
$mail->subject = 'Xion-Solutions';
$mail->setFrom = $email;
$mail->Body = $message;
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->isSMTP();
$mail->Host = 'mail.xionproaudio.com';
$mail->SMTPAuth = true;
$mail->Username = 'info@xionproaudio.com';
$mail->Password = 'INdia@1991$';
$mail->Port = 465;
$mail->IsHTML(true);
if($mail->send()){
echo 1;
}else{
echo 0;
}
}
} else {
echo json_encode(array('info' => 'error', 'msg' => __MESSAGE_EMPTY_FILDS__));
}
?>
我將第二次使用Yii的內置mailer類的調用-如果您要使用框架,請使用該框架。
與PHPMailer一樣,請執行以下操作: 閱讀PHPMailer故障排除指南 ,將代碼基於PHPMailer隨附的示例 ,並使用最新版本 。
這里有許多基本問題。
如果您將代碼基於所提供的示例之一,則可以避免大多數此類問題。 您需要修復的主要部分是:
$mail->addAddress('user@gmail.com', 'Xion-Solutions');
$mail->setFrom('user@gmail.com', 'Xion-Solutions');
$mail->addReplyTo($email, $name);
$mail->Subject = 'Xion-Solutions';
$mail->SMTPDebug = 2;
為什么要推出自己的驗證器? PHPMailer具有一個更好的內置函數,您可以靜態調用,但是無論如何它都會自動應用於自動接受地址的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.