我想用php發送郵件。我正在使用wampserver2.2。而我的PHP版本是5.4.3無法使用PHP發送郵件
這裏是我試過的代碼:
<?php
if(isset($_POST['submit']))
{
$YourName = mysql_real_escape_string($_POST['YourName']);
$From = mysql_real_escape_string($_POST['Email']);
$Subject = mysql_real_escape_string($_POST['Subject']);
$Message = mysql_real_escape_string($_POST['message']);
$myEmailAdr = "[email protected]";
if (preg_match('/^[a-zA-Z][a-zA-Z0-9_-][email protected][a-zA-Z]+[.]{1}[a-zA-Z]+$/', $From))
{
$headers = 'From: '.$From."\r\n".'Reply-To: '.$From;
$Message = str_replace("\n.", "\n..", $Message);
try
{
ini_set("SMTP","ssl:smtp.gmail.com");
ini_set("smtp_port","465");
$send = mail($myEmailAdr, $Subject, $Message, $headers); // line 24
}
catch(PDOException $e)
{
$error = $e->getMessage();
echo $error;
}
}
else
{
echo "Error in Mail Address Format";
}
}
?>
的問題是我收到以下錯誤,當我嘗試使用它。第24行表示郵件功能。
Warning: mail(): Failed to connect to mailserver at "ssl:smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\UMVSS_Website\ContactScript.php on line 24
既不''ini_set'或'mail'拋出一個'PDOException' – Rob