有人可以帮助我用PHP发送邮件

时间:2012-03-02 06:58:04

标签: php email

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

    global $error;

    $from  = $_REQUEST['from'];
    $from_name = $_REQUEST['from_name'];
    $subject  = $_REQUEST['subject'];
    $body = $_REQUEST['body'];
    $is_gmail  = $_REQUEST['is_gmail'] =true;
    $to  = $_REQUEST['to'];
  $to  = "defaultemail@live.in"; // used for testing only
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPAuth = true; 
    if ($is_gmail) {
        $mail->SMTPSecure = 'tls';
        $mail->Host = 'smtp.ks101.fdsfd.eu';
        $mail->Username = 'testing@edsfdsd.de';  
        $mail->Password = "pass";   
        $mail->SMTPDebug = 1;
    } else {
        $mail->Host = SMTPSERVER;
        $mail->Username = SMTPUSER;  
        $mail->Password = SMTPPWD;
    }        
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo;
        echo(false);
        return false;
    } else {
        $error = 'Message sent!';
        echo(true);
        return true;
    }
?>

我向托管服务提供商展示以下代码,他们告诉我它应该有效。我尝试上传它,但它没有用。

当我尝试使用实际的服务器时,我遇到了错误(可能是PHP服务器)。

<br />
<b>Warning</b>:  stream_socket_enable_crypto() [<a href='streams.crypto'>streams.crypto</a>]: this stream does not support SSL/crypto in <b>/home/www/web420/html/test/PHPMailer/class.smtp.php</b> on line <b>197</b><br />
SMTP -> ERROR: RSET failed: 
<br />Language string failed to load: tls

当我尝试使用我的服务器时,我遇到了相同代码(IIS 7)的错误

<br />
<b>Warning</b>:  stream_socket_enable_crypto() [<a href='streams.crypto'>streams.crypto</a>]: this stream does not support SSL/crypto in <b>C:\inetpub\vhosts\test.com\subdomains\test\httpdocs\appbounce\PHPMailer\class.smtp.php</b> on line <b>197</b><br />

我不知道网站使用的是什么服务器。我得到了不同的2个错误。请有人验证我的代码中是否存在问题。究竟我需要做什么。

感谢

1 个答案:

答案 0 :(得分:0)

一些快速提示

添加此

$mail->Port = 465;

更改此

$mail->SMTPSecure = "ssl";

如果两者都不起作用......那么托管部分的路由器级别认证问题