使用此代碼,如果你在這個整合面臨的任何問題,請讓我知道..
<?php
if(!empty($_POST))
{
$name = $_POST['name'];
/*/ this is the email we get from visitors*/
$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
/*//-->MUST BE 'https://';*/
header("Content-type: application/json");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *.ampproject.org");
header("AMP-Access-Control-Allow-Source-Origin: ".$domain_url);
/*/ For Sending Error Use this code /*/
if(!mail("[email protected]" , "Test submission" , "email: $name <br/> name: $name" , "From: $name\n ")){
header("HTTP/1.0 412 Precondition Failed", true, 412);
echo json_encode(array('errmsg'=>'There is some error while sending email!'));
die();
}
else
{
/*/--Assuming all validations are good here--*/
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
echo json_encode(array('successmsg'=>$_POST['name'].'My success message. [It will be displayed shortly(!) if with redirect]'));
die();
}
}?>
感謝回答,代碼顯然是可行的,因爲當我點擊發送它出現類「用戶有效的amp-form-submit-success」,但沒有任何東西到達我的電子郵件。可能會丟失什麼? 謝謝 – ctovelox
沒有看到你的代碼不能說什麼...... – BlueSuiter
我使用的是wordpress AMP插件,一切看起來都很好我用你的PHP代碼,我改變了把電子郵件的一部分,我把它加載到主我的網站文件夾wp。 我改變了這部分我的電子郵件:'!mail(「[email protected]」' 我的表單是 '
' 不攜帶 – ctovelox