尝试发送电子邮件,但我不能

时间:2014-08-16 22:05:36

标签: php email smtp

我无法发送电子邮件,我花了几个小时没有解决方案。我试图搜索php.ini文件,我发现smtp = localhost和port = 25.我已经包含了PHPMailerAutoload.php,class.phpmailer来自Github的.php和class.smtp.php但似乎没什么用。我得到的错误是:1)SMTP connect()失败。 2)无法实现邮件功能的安装。

提前致谢。

以下是我的代码:

<?php
        session_start();

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

    define('PASS', 'secret');

    if(isset($_SESSION['email'])){
        $email = $_SESSION['email'];
    }

    if(isset($_SESSION['company_name'])){
        $comp_name = $_SESSION['company_name'];
    }

    if (isset($_SESSION['endDate'])){
        $endDate = $_SESSION['endDate'];
    }

    if(isset($_SESSION['startDate'])){
        $startDate = $_SESSION['startDate'];
    }

    echo "Company Name " . $comp_name;
    echo "From " . $startDate . " to " . $endDate;

    $from_name="Mario";
    $from = "nikolaou_marios@hotmail.com";
    $to = $email;
    $subject = $comp_name;
    $message = "Start date : " . $startDate . " End Date : " . $endDate;


    $mail = new PHPMailer;
    $mail -> isSMTP();
    $mail -> SMTPAuth = true;

    $mail -> Host = 'localhost';
    $mail -> Username = 'marios.nikolaou87@gmail.com';
    $mail -> Password = 'PASS';
    $mail -> CharSet = 'UTF-8';

    $mail -> SMTPSecure = 'tsl';
    $mail -> Port = 25;

    //$mail -> FromName = $from_name;
    $mail -> setFrom = $from;
    $mail -> addAddress($to);

    $mail -> Subject = $subject;
    $mail -> Body = 'asdasd';

    if(!$mail->Send()){

      echo "Message could not be sent.<br />";
      echo "Mailer error " . $mail -> ErrorInfo;

    }else{

      echo "Message sent.";

    }
?>

0 个答案:

没有答案