托管提供商说网站电子邮件表格必须是smtp出于安全原因而不是php脚本

时间:2014-01-03 07:21:59

标签: php email smtp

我尝试将我的php邮件脚本设置为SMTP邮件脚本,因为我的托管服务提供商不允许在没有验证的情况下发送邮件。 我的访客从我的网站发送电子邮件到我的域电子邮件帐户。 我必须发送SMTP邮件,但我无法将该脚本转换为php邮件表单。 以下是代码:

<?    
if($_POST[CheckTavsiye]=='Evet')    
{     
$Kactive = '1';    
$body ="Full Name:  ".$_POST['name']." ".$_POST['surname']."\n";    
$body .="Email  : ".$_POST['email']."\n";    
$body .="Phone number : ".$_POST['phone']."\n";    
$body .="Property No:   ".$_POST['pno']."\n";    
$body .="Country : ".$_POST['country']."\n";    
$body .="Comments :   ".$_POST['mortgage']."\n";    
$from       ="example<info@domain.com>";    
$to         ="info@domain.com";    
$subject    ="example";    
$as_from    ="example<info@domain.com>";    
$as_to      = $_POST['email'];    
$as_subject ="example";    
$as_body    = "Hi,    

Your enquiry has been received. 

";    

include("mailsend.php");    
?>    

托管提供的脚本和文件:

  • index.html
  • send.php
  • 包含文件夹(class.php,smtp.php)

以下是代码:send.php

<?php    

$mail_adress    = "";    
$mail_password  = "";    
$send_adress    = "";    
$domain_adress  = "";   //without the www    

require("include/class.php");    
$mail = new PHPMail();    
$mail->Host       = "smtp.".$domain_adress;    
$mail->SMTPAuth   = true;    
$mail->Username   = $mail_adress;    
$mail->Password   = $mail_password;    
$mail->IsSMTP();
$mail->AddAddress($send_adreds);    
$mail->From       = $mail_adress;    
$mail->FromName   = $mail_adress;    
$mail->Subject    = $_POST["MailSubject"];    
$mail->Body       = $_POST["mailadress"]."\n".$_POST["Mail"];    
$mail->AltBody    = "";    

if(!$mail->Send()){    
echo "<html>\n";    
echo "<head>\n";    
echo "<meta http-equiv=\"Content-Language\" content=\"tr\">\n";    
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\">\n";    
echo "<meta name=\"Author\" content=\"IsimTescil Destek\">\n";    
echo "<title> IsimTescil - Destek </title>\n";    
echo "</head>\n";    
echo "<body>\n";    
echo "<center>\n";    
echo "<hr width=\"500\" color=\"#C0C0C0\" style=\"border-style: double; border-width: 3px\">\n";    
echo "<font face=\"Verdana\" style=\"font-size: 8pt\"><b>[</b> <font color=\"#0000FF\">\n";    
echo "Mesajýnýz Gönderilirken bir hata oluþtu. Sunucudan gelen cevap aþaðýdaki gibidir:\n";    
echo "</font> <b>]</b></font>\n";    
echo "<br><font face=\"Verdana\" style=\"font-size: 8pt\"><b>[</b> <font color=\"#0000FF\">\n";    
echo "Hata: " . $mail->ErrorInfo;    
echo "</font> <b>]</b></font>\n";    
echo "<hr width=\"500\" color=\"#C0C0C0\" style=\"border-style: double; border-width: 3px\">\n";    
echo "</center>\n";    
echo "</body>\n";    
echo "</html>\n";    
exit;    
}    

echo "<html>\n";    
echo "<head>\n";    
echo "<meta http-equiv=\"Content-Language\" content=\"tr\">\n";    
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\">\n";
echo "<meta name=\"Author\" content=\"IsimTescil Destek\">\n";    
echo "<title> IsimTescil - Destek </title>\n";    
echo "</head>\n";    
echo "<body>\n";    
echo "<center>\n";    
echo "<hr width=\"500\" color=\"#C0C0C0\" style=\"border-style: double; border-width: 3px\">\n";    
echo "<font face=\"Verdana\" style=\"font-size: 8pt\"><b>[</b> <font color=\"#0000FF\">\n";    
echo "Mesajýnýz Gönderilmiþtir.\n";    
echo "</font> <b>]</b></font>\n";    
echo "<hr width=\"500\" color=\"#C0C0C0\" style=\"border-style: double; border-width: 3px\">\n";    
echo "</center>\n";    
echo "</body>\n";    
echo "</html>\n";    

?>

1 个答案:

答案 0 :(得分:1)

您可以使用phpmailer进行SMTP电子邮件发送:

这个配置为PHP邮件程序中的gmail。您可以像这样创建SMTP配置。

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.gif');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>