2013-09-26 54 views
-1

我想从我的PHP应用程序发送邮件。以下是我的代码。邮件没有被发送与PHP

<?php 
    error_reporting (E_ALL); 
    ini_set ('SMTP', 'smtp.live.com'); 
    ini_set ('smtp_port', '587'); 
    ini_set ('sendmail_from', '[email protected]'); 

    $to = "[email protected]"; 
    $subject = "Test mail"; 
    $message = "Hello! This is a simple email message."; 

    $headers = "From:[email protected]\r\n"; 
    $headers .= "X-Mailer: php\r\n"; 
    $headers .= "Reply-To:[email protected]\r\n"; 
    $headers .= 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $result = mail($to,$subject,$message,$headers); 
    if($result) 
    { 
    echo "Mail Sent."; 
    } 
    else 
    { 
    echo ("error"); 
    } 
    ?> 

它给我留言“邮件发送”,所以我希望收到邮件......但不要。假设收到邮件可能会有延迟,我现在等了3天。也检查了我的垃圾,但没有...所以我相信我的代码不是发送邮件....不知道为什么。

我可能错过了一些设置...但由于这是我第一次使用PHP邮件,我不知道什么设置丢失。在阅读Mail的文档...没有找到任何这样的要求/设置。任何帮助将非常感激。

+0

不知道,你可以使用smtp.live.com从你的脚本,他们可能不会接受你的连接。 – Mario

+0

你在设置你的hotmail用户名/密码吗?这个问题可能有助于[链接](http://stackoverflow.com/questions/9430412/how-to-set-smtp-username-and-password-using-ini-set) – Re0sless

+0

希望这个问题可能现在被整理出来。是吗? – Jinandra

回答

-1

如果不进行身份验证,则无法使用smtp.live.com。

+0

增加了以下代码 ini_set('smtp_user','[email protected]'); ini_set('smtp_password','mypass'); ini_set('smtp_start_tls','1'); 但仍然没有邮件。而且,当我尝试发送邮件而不验证自己时,是否应该给出错误? –

0

如果你不介意使用PHPMailer的LIB试试这个:

<?php 
    require("PHPMailer_5.2.4/class.phpmailer.php"); 

    $mail = new PHPMailer(); 
    $mail->SMTPDebug = true; 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->SMTPAuth = true; // SMTP authentication 
    $mail->Host  = "StartTLS://smtp.live.com"; // SMTP server 
    $mail->Port  = 587; // SMTP Port 
    $mail->Username = "username"; // SMTP account username 
    $mail->Password = "xxx";  // SMTP account password 

    $mail->SetFrom('from_emailid', 'yourname'); // FROM 
    $mail->AddReplyTo('replyto_emailid', 'name'); // Reply TO 

    $mail->AddAddress('recepeint_emailid'); // recipient email 

    $mail->Subject = "First SMTP Message"; // email subject 
    $mail->Body  = "Hi! \n\n This is my first e-mail sent through live SMTP using PHPMailer."; 

    if(!$mail->Send()) { 
     echo 'Message was not sent.'; 
     echo 'Mailer error: ' . $mail->ErrorInfo; 
    } else { 
     echo 'Message has been sent.'; 
    } 
+0

我刚刚尝试过并测试了代码,它对我来说工作得很好。你能否指出你收到的任何特定错误。 – Jinandra