设置php mail()函数的SMTP详细信息 [英] Setting SMTP details for php mail () function
本文介绍了设置php mail()函数的SMTP详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找答案,并尝试了许多事情来解决这个问题。
I have been looking for an answer and tried many things to this problem.
我的脚本在我的webhost上工作正常,但是当将其移动到另一个专用服务器时邮件永远不会交付。现在我需要设置SMTP服务器,但是找不到它。
My script works fine on my webhost but when moving it to an other dedicated server the mail never gets delivered. Now i need to set the SMTP server but don't get it right.
使用Gmail应用程序btw。这是代码如何。
Using Gmail apps btw. This is how the code looks like.
<?php
if(!$_POST) exit;
$email = $_POST['email'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("@",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','telephone','message');
$required = array('name','email','telephone','message');
$your_email = "xxx@example.com";
$email_subject = "New Messag: ".$_POST['subject'];
$email_content = "New message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'telephone') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "user@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
?>
那么我如何设置SMTP设置?
So how do i set the SMTP settings right?
推荐答案
仅在Windows下: 您可以尝试使用 ini_set()
功能 SMTP
文件 和 smtp_port
文档 设置:
Under Windows only: You may try to use ini_set()
functionDocs for the SMTP
Docs and smtp_port
Docs settings:
ini_set('SMTP', 'mysmtphost');
ini_set('smtp_port', 25);
这篇关于设置php mail()函数的SMTP详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文