有人可以帮我发邮件给PHP [英] Can someone help me to send mail in PHP
问题描述
<?php
require(./ PHPMailer / class.phpmailer.php);
全局$错误;
$ 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; //仅用于测试
$ mail = new PHPMailer();
$ mail-> IsSMTP();
$ mail-> SMTPAuth = true;
if($ is_gmail){
$ mail-> SMTPSecure ='tls';
$ mail-> Host ='smtp.ks101.fdsfd.eu';
$ mail->用户名='testing@edsfdsd.de';
$ mail-> Password =pass;
$ mail-> SMTPDebug = 1;
} else {
$ mail-> Host = SMTPSERVER;
$ mail->用户名= SMTPUSER;
$ mail-> Password = SMTPPWD;
}
$ mail-> SetFrom($ from,$ from_name);
$ mail-> Subject = $ subject;
$ mail-> Body = $ body;
$ mail-> AddAddress($ to);
if(!$ mail-> Send()){
$ error ='邮件错误:'$ mail-> ErrorInfo;
echo(false);
返回false;
} else {
$ error ='发送信息!';
echo(true);
返回true;
}
?>
我向托管提供商显示以下代码,他们告诉我它应该工作。我尝试上传它,但它没有工作。
当我尝试在网站应该是(可能是PHP服务器)的实际服务器时,我收到错误。
< br />
< b>警告< / b> ;: stream_socket_enable_crypto()[< a href ='streams.crypto'> streams.crypto< / a>]:此流不支持& b个/home/www/web420/html/test/PHPMailer/class.smtp.php< / b个在< b> 197< / b>< br />
SMTP - >错误:RSET失败:
< br />语言字符串加载失败:tls
当我尝试在我的服务器上我得到相同代码的错误(IIS 7)
< br />
< b>警告< / b> ;: stream_socket_enable_crypto()[< a href ='streams.crypto'> streams.crypto< / a>]:此流不支持& b个C:\inetpub\vhosts\test.com\subdomains\test\httpdocs\appbounce\PHPMailer\class.smtp.php< / b个在< b> 197< / b>< br />
我不知道网站使用的是什么服务器。我有不同的2错误。请有人验证,如果他们是我的代码中的问题。我需要做什么。
谢谢
提示
添加此
$ mail-> Port = 465 ;
更改此
code> $ mail-> SMTPSecure =ssl;
如果两者都不工作....那么主机部分的路由器级验证问题>
<?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;
}
?>
I show the following code to hosting provider and they tell me it should work. I try to upload it but it's not worked.
I got the error when I try on the actual sever where site should be (maybe PHP server).
<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
When I try on my server I got error for same code (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 />
I don't know what is the server used by the website. I got different-2 errors. Please someone verify that if their is a problem in my code. What exactly I need to do.
thanks
some quick tips
Add this
$mail->Port = 465;
change this
$mail->SMTPSecure = "ssl";
if both of not work.... then problem with router level authentication at hosting part
这篇关于有人可以帮我发邮件给PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!