我在AMP HTML形式,POST操作;電子郵件的PHP文件使用Sendgrid API。 I was try headers response for Json redirect,但是,沒有工作。AMP PHP聯繫表不重定向(谷歌AMP)
爲此我採用JavaScript重定向(是的,我知道,這產生AMP驗證錯誤,但我需要重定向到感謝頁面跟蹤在線轉化)。
PHP文件工作得很好,所有的郵件都發送給它的,但內部消除JavaScript重定向,只能用DIV成功或錯誤的電子郵件發送,只有我看到錯誤發送電子郵件,但是,自相矛盾,所有的郵件都發送它的無通過Sendgrid API問題LOL)。
因此,我需要使用正確的PHP標頭Json響應(無JavaScript)重定向HTML聯繫表單,以跟蹤在線轉換並正確驗證我的AMP HTML源代碼。在其他情況下,我認爲它是非常有用的製作從PHP文件正確重定向成功提交後(以我嘗試在PHP頭位置重定向,但是,不工作... ...)
形式:
<form method="post"
class="p2"
action-xhr="//example.com/path/themex/amp-theme/path/file.php"
target="_top">
<div class="ampstart-input inline-block relative m0 p0 mb3">
<input type="text"
class="block border-none p0 m0"
name="name"
placeholder="Nombre"
required>
<input type="tel"
class="block border-none p0 m0"
name="tel"
placeholder="Teléfono"
required>
</div>
<select name="store"
id="store">
<option value="San Antonio">San Antonio</option>
<option value="Santiago Centro">Santiago Centro</option>
<option value="San Bernardo">San Bernardo</option>
<option value="Puente Alto">Puente Alto</option>
<option value="Rancagua">Rancagua</option>
<option value="Chillán">Chillán</option>
<option value="Talca">Talca</option>
<option value="Concepción">Concepción</option>
<option value="Los Ángeles">Los Ángeles</option>
<option value="Linares">Linares</option>
<option value="Valdivia">Valdivia</option>
<option value="Temuco">Temuco</option>
<option value="Puerto Montt">Puerto Montt</option>
</select>
<label for="sucursal"
class="absolute top-0 right-0 bottom-0 left-0">Selecione una Ciudad</label>
<input type="submit"
value="Enviar"
class="ampstart-btn caps" onclick="redirectThanks()">
\t \t \t \t <script>
function redirectThanks() {
window.location = "https://www.example.com/thanks-page/amp/";
}
</script>
<div submit-success>
<template type="amp-mustache">
Success! Thanks {{name}} for trying the
<code>amp-form</code> demo! Try to insert the word "error" as a name input in the form to see how
<code>amp-form</code> handles errors.
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Error! Thanks {{name}} for trying the
<code>amp-form</code> demo with an error response.
</template>
</div>
</form>
PHP後:
<?php
/*SendGrid Library*/
require_once ('vendor/autoload.php');
/*Post Data*/
$name = $_POST['name'];
$tel = $_POST['tel'];
$store = $_POST['store'];
/*Content*/
$from = new SendGrid\Email("Sender", "[email protected]");
$subject = "My Subject {$store}";
$to = new SendGrid\Email("Recipient", "[email protected]");
$content = new SendGrid\Content("text/html", "
\t Name: {$name}<br>
\t Phone: {$tel}<br>
\t Store: {$store}
\t ");
/*Send the mail*/
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = ('mysendgridapikeyhash');
$sg = new \SendGrid($apiKey);
/*Response*/
$response = $sg->client->mail()->send()->post($mail);
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: https://www.example.com/");
header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
header ('AMP-Redirect-To: https://www.example.com/thanks-page/amp/');
?>
任何想法,請?