PHPMailer发送电子邮件失败

时间:2015-02-03 13:00:08

标签: php email phpmailer

在验证了我在validate_email函数中收到数据变量信息的所有信息后,尝试通过php邮件程序将电子邮件表单信息发送到特定的电子邮件帐户。

我已经应用了php邮件代码,并希望将数据变量的所有信息发送到特定的电子邮件帐户。

但它显示我错误

<?php

   $name = $email = $query = "";
   $name_err = $email_err = $query_err = "";

   if ($_SERVER ["REQUEST_METHOD"] == "POST") {

    if (empty ( $_POST ["name"] )) {
        $name_err = 'Please Enter Your Name';
    } else {
        $name = validate_email ( $_POST ["name"] );
    }
    if (empty ( $_POST ["email"] )) {
        $email_err = 'Please Enter Your Email Id';
    } else {
        $email = validate_email ( $_POST ["email"] );

        if (! filter_var ( $email, FILTER_VALIDATE_EMAIL )) {
            $email_err = "Invalid email format";
        }
    }
    if (empty ( $_POST ["query"] )) {
        $query_err = 'Please type your query';
    } else {
        $query = validate_email ( $_POST ["query"] );
    }
    }

    function validate_email($data) {
    $data = trim ( $data );
    $data = stripslashes ( $data );
    $data = htmlspecialchars ( $data );


    $subject = "Visitor Query";
    $from = "007shiva007@gmail.com"; // example a@b.com
    $password = '************';

    //require ("PHPMailer/PHPMailerAutoload.php");
    require ("phpmailer/class.phpmailer.php");
    require ("phpmailer/class.smtp.php");

    $mail = new PHPMailer ();

    $mail->IsSMTP ();
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->SMTPDebug = 1;

    $mail->Host = 'smtp.gmail.com'; // sets SMTP server
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;

    $mail->Username = $from; // SMTP username
    $mail->Password = $password; // SMTP password

    $mail->AddAddress ( "partyushgoyal@gmail.com" );
    // $mail->AddAddress ( "choudharypadam3@gmail.com" );
    // $mail->AddReplyTo ( "choudharypadam3@gmail.com", "Reply Address" );

    $mail->Subject = $subject;
    $mail->Body = $data;
    // $mail->AltBody = 'Padma Industries';
    $mail->From = $from;
    //$mail->FromName = 'Padmaindustries.in';
    $mail->ContentType = "text/html";

    $result = $mail->Send ();

    //header ( "location: index.php" );

    //return $data;
    }

    ?> 

0 个答案:

没有答案