0
每當我點擊發送按鈕它總是觸發0值(否則部分)。每當我點擊發送按鈕它總是發射0值(其他部分)。我是無法在Yii 2.0框架中藉助PHPMailer在服務器上發送郵件。我無法通過Yii 2.0框架中的PHPMailer幫助在服務器上發送郵件。請提前幫助我,並感謝您。我無法發送郵件的幫助哦PHPMailer在yii 2.0
<?php
//Check e-mail validation
function check_email($email){
if([email protected]("^[_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 = "[email protected]";
$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 = '[email protected]';
$mail->Password = '[email protected]$';
$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__));
}
?>
那麼你會得到什麼錯誤? – ArtOsi
你爲什麼不使用Yii內建的Mailer? http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html – kyle
我們需要你得到的錯誤。嘗試看看$ mail-> ErrorInfo說 – Chux