我想用php發送電子郵件,但無法做到,而我正在將數據存入MySQL
數據庫。PHP使用郵件功能發送電子郵件
我發佈了我的整個代碼,請檢查並讓我知道錯誤在哪裏。
$objConnect = mysql_connect("localhost","username","pwd");
$objDB = mysql_select_db("database");
$strName = $_POST["name"];
$strEmail = $_POST["email"];
$to = $strEmail;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$strSQL = "insert into data (name, email) VALUES ('".$strName."','".$strEmail."')";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Message'] = "Cannot save data!";
}
else
{
mail($to, $subject, $message, $headers);
$arr['StatusID'] = "1";
$arr['Message'] = "Data saved successfully";
}
mysql_close($objConnect);
echo json_encode($arr);
執行'var_dump(mail($ to,$ subject,$ message,$ headers))'並查看它返回的內容。 –
你是否在本地進行測試? –
@Sougata變得無法上傳 – Sun