简体   繁体   English

我无法在yii 2.0中发送带有帮助的邮件哦PHPMailer

[英]i am unable to send mail with help oh PHPMailer in yii 2.0

whenever I click on send button it always fired 0 value (else part).whenever I click on send button it always fired 0 value (else part).I am unable to send mail on a server with help of PHPMailer in Yii 2.0 framework..I am unable to send mail on a server with help of PHPMailer in Yii 2.0 framework. 每当我单击发送按钮时,它总是会触发0值(其他部分)。每当我单击发送按钮时,它总是会触发0值(其他部分)。我无法在Yii 2.0框架中借助PHPMailer在服务器上发送邮件。 。我无法在Yii 2.0框架中借助PHPMailer在服务器上发送邮件。 please help me and thank you in advance.! 请帮助我,谢谢你!

<?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__));
    }
 ?>

I'll second the call to use Yii's built-in mailer class - if you're going to use a framework, use the framework. 我将第二次使用Yii的内置mailer类的调用-如果您要使用框架,请使用该框架。

As always with PHPMailer: Read the PHPMailer troubleshooting guide , base your code on the examples provided with PHPMailer , use the latest version . 与PHPMailer一样,请执行以下操作: 阅读PHPMailer故障排除指南 ,将代码基于PHPMailer随附的示例 ,并使用最新版本

Many basic problems here. 这里有许多基本问题。

  • You're not giving it an address to send to. 您没有给它发送地址。
  • You're forging the from address. 您正在伪造发件人地址。
  • You're using your own address as the reply-to. 您使用自己的地址作为回复对象。
  • You're trying to set property names that are methods. 您正在尝试设置作为方法的属性名称。
  • You're ignoring that PHP property names are case sensitive. 您忽略了PHP属性名称区分大小写。
  • You're not generating any error message output if sending fails. 如果发送失败,则不会生成任何错误消息输出。
  • You've set debug output to only show client-side messages, so you can't see what's going on. 您已将调试输出设置为仅显示客户端消息,因此您看不到发生了什么。

If you'd based your code on one of the examples provided you would have avoided most of these problems. 如果您将代码基于所提供的示例之一,则可以避免大多数此类问题。 The main parts you need to fix are: 您需要修复的主要部分是:

$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;

Why roll your own validator? 为什么要推出自己的验证器? PHPMailer has a better one built in that you can call statically, but it's applied everywhere it accepts addresses automatically anyway. PHPMailer具有一个更好的内置函数,您可以静态调用,但是无论如何它都会自动应用于自动接受地址的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM