PHPMailer不发送

时间:2015-03-07 09:07:31

标签: php phpmailer

我正在尝试使用PHP邮件程序创建联系表单。 它没有显示错误,但我没有收到电子邮件。我也尝试使用mail()函数,但它也无法正常工作..

这是我的PHP代码

<?php

if (!empty($_POST['email']) && !empty($_POST['message'])){
$errors = array();
$to = "kim@t-i-c.asia";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['message'];
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:".$email;

    require_once 'phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    // Set UP SMTP
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->SMTPSecure ='ssl';
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465;
    $mail->Encoding = '7bit';

    //Authentication
    $mail->Username = "kuyakimpoy010@gmail.com";
    $mail->Password = "password";

    // Compose
    $mail->SetFrom ("client@t-i-c.asia", $email);
    $mail->AddReplyTo("client@t-i-c.asia", $email);
    $mail->Subject = $subject;
    $mail->MsgHtml($body);
    $mail->addAddress($to,'Kim Carlo'); //recipient
    $mail->Send();

    if($mail){
        $errors = "<font style='font-size:18px; color:#000000; line-height:150%'>Thank you!<br><br></font><font style='font-size:16px;''>We have received you message.<br>Your opinions and comments are very important to us and we read every message that we receive.<br>Our goal is to improve our service in any way we can, and we appreciate your taking the time to fill<br>
        out our feedback form.<br><br></font>";
    }else{
        $errors = "<font style='font-size:18px; color:#000000; line-height:150%'>There was a problem sending your message.<br><br>Please try again later.</font>";

    }
    header("refresh:10; url=/../contactform.php");
}else{
$errors = "<font style='font-size:18px; color:#000000; line- height:150%'>Please fill in email address and message fields<br><br></font>";
}

?>

这是我的联系表格

<form name="contact" method="POST" action="php/feedback.php">
            <label>Name:</label><br>
            <input type="text" name="name"/><br><br>

            <label>Email Address:<font color="red">*</font></label><br>
            <input type="email" name="email"/><br><br>

            <label>Subject:</label><br>
            <input type="text" name="subject"/><br><br>

            <label>Message:<font color="red">*</font></label><br>
            <textarea cols="45" rows="10" name="message"></textarea><br><br>
            <input type="submit" value="Send Message">

1 个答案:

答案 0 :(得分:0)

我通过删除此行解决了它。

$mail->IsSMTP();

感谢那些时间......