我想使用此 PHP MAILING 脚本而不是通过 sendmail 通过SMTP发送邮件,因为我的主机拒绝了所有垃圾邮件,因此我不检查垃圾邮件文件夹,因为每天都有大量垃圾邮件。
我只想知道将代码放置在哪里,该代码将使用此SMTP脚本而不是sendmail /
使用SMTP登录名发送邮件我尝试添加一些类似的东西
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";
但是这些没有用,实际上它破坏了整个代码本身,
编辑:我也尝试添加此内容,从此处阅读另一个已回答问题的答案,这也破坏了代码本身,但不起作用。
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
原始代码
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG .= "E-mail is required ";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
// change this to fit !
$EmailTo = "demo@domain.com";
$Subject = "New Message from MENTOR";
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Somethin went wrong...";
} else {
echo "An error has ocurred!";
//echo $errorMSG; Enable if you want full details of php error
}
}
?>