我试图通过服务器PHP 7
PDO
扩展名和xampp
作为本地服务器发送电子邮件。
当我打开电子邮件框时,我没有收到电子邮件,也没有在服务器端显示任何错误。看起来服务器说发送了电子邮件,但电子邮件框什么也没收到。
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: X-Custom-Header, Origin, Content-
Type , Authorisation , X-Requested-With");
header("Content-Type: application/json; charset=UTF-8 ");
$json = file_get_contents('php://input');
$decoded = json_decode($json, true);
$tab = $decoded['tab'];
$b = false;
foreach ($tab as $item) {
if (!is_numeric($item['idprod']) || !is_numeric($item['prix']) ||
!is_numeric($item['qte']) || !is_numeric($item['refCmd']) ) {
$b = true;
}
}
function conn()
{
$dbhost = "localhost";
$user = "root";
$pass = "";
$db = "smart";
$conn = new PDO('mysql:host=localhost;dbname=smart', $user, $pass);
return $conn;
}
if($b == true){
die;
}else{
$db = conn();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$p = $db->prepare("INSERT INTO regrouper (refCommande, refProduit, prixP,
qteP)
VALUES(:refCmd, :idprod, :prix, :qte)");
foreach ($tab as $item) {
$p->execute($item);
}
$to_email = 'faresbenslama95@gmail.com';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
$headers = 'From: ssd.mahdia@gmail.com';
$res = mail($to_email, $subject, $message, $headers);
echo $res? 'mail returned true':'mail returned false';
echo json_encode(true);
}
?>
我希望在从服务器收到的我的Gmail框中找到一封电子邮件。