[英]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.