PHP的邮件程序谷歌smtp的工作本地主机不工作在现场 [英] Php mailer google smtp working on localhost not working on live site
问题描述
为此,我使用phpmailer库。
我的代码如下:
函数smtpmailer($ to,$ from,$ from_name,$ subject,$正文){
global $ error;
$ username =xyz@demo.net;
$ password =1234567;
$ mail = new PHPMailer(); //创建一个新对象
$ mail-> IsSMTP(); //启用SMTP
$ mail-> SMTPDebug = 1; //调试:1 =错误和消息,2 =仅消息
$ mail-> SMTPAuth = true; //启用认证
$ mail-> SMTPSecure ='ssl'; //启用安全传输需要GMail
$ mail-> Host ='smtp.gmail.com';
$ mail->端口= 465;
$ mail->用户名= $ username;
$ mail->密码= $密码;
$ mail->优先权= 1; //最高优先级 - 电子邮件优先级(1 =高,3 =正常,5 =低)
$ mail-> CharSet ='UTF-8';
$ mail->编码='8位';
$ mail-> ContentType ='text / html;字符集= UTF-8\r\\\
;
$ mail-> SetFrom($ from,$ from_name);
$ mail-> Subject = $ subject;
$ mail-> Body = $ body;
$ mail-> AddAddress($ to);
$ mail-> IsHTML(true);
$ mail-> WordWrap = 900;
if(!$ mail-> Send()){
$ error ='Mail error:'。 $ MAIL-> ERRORINFO;
返回false;
} else {
$ error ='发送信息!';
$ mail-> SmtpClose();
返回true;
这段代码在本地主机上正常工作,但我将它上传到mysite那么它显示以下错误:
SMTP - >错误:无法连接到服务器:连接超时(110)SMTP连接()失败。
我的网站托管在文件夹中,例如
请帮我弄清楚问题并解决它
谢谢Advance ...
解决方案我收到了一些托管服务提供商不支持邮件的外部主机的问题。你必须问你的托管支持天气,他们允许外部主机或不。
我使用我的托管提供商的imap设置,现在解决了
希望这可以帮助别人!!
I'm trying to send mail to registered user after registration.
For that I m using phpmailer library.
my code is as below:
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$username = "xyz@demo.net";
$password = "1234567";
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = $username;
$mail->Password = $password;
$mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->WordWrap = 900;
if (!$mail->Send()) {
$error = 'Mail error: ' . $mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
$mail->SmtpClose();
return true;
}
This code works fine on localhost but i uploaded it to mysite then it is showing following error:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed.
my site is hosted in folder eg (myhost.in/mysite).
Please help me to figure out problem and to solve it
Thanks in Advance...
解决方案 I got the issue some of hosting provider not supporting external host for mail. you have to ask your hosting support weather they allow external host or not.
I used imap settings of my hosting provider and now it is solved
hope this will help someone!!
这篇关于PHP的邮件程序谷歌smtp的工作本地主机不工作在现场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!