发送PHP确认电子邮件联系表格而不使用操作=""

时间:2018-05-22 16:04:12

标签: php email contact-form

我需要更换网站上的联系表单,我曾经使用过上一个联系表单中通过PHP发送的确认电子邮件,因为属性操作是空的,所以我可以将php代码保存在同一页面上。这是之前的联系表格:

<form action="" method="POST">

    <input type=hidden name="oid" value="00Db0000000IeRo">
    <input type=hidden name="retURL" value="http://business.mytaxi.ie/thankyou.php">

    <input id="email" maxlength="80" name="email" size="20" required="" type="email" value="" oninvalid="InvalidMsg(this);" oninput="InvalidMsg(this);" placeholder="email"/>
    <a href="" class="bannerbutsub" title="get started for free.">get started for free.</a>
    <input type="submit" name="submit" value="Register Interest" title="Register Interest" class="bannerbutsub">

</form>

这是我的PHP代码:

if($_POST['email']){
    $q = "INSERT INTO entries (email, datetime) VALUES ('".mysql_real_escape_string($_POST['email'])."',now())";
    $r = mysql_query($q) or die(mysql_error());


// sending confirmation email

$to = $_POST['email'];
$subject = 'Registration Confirmation';
$from = 'ireland.business@mytaxi.com';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Create email headers
$headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<p>Hi there,</p>';
$message .= '<p>Thanks for registering your interest in mytaxi | Business.</p>';
$message .= '<p>Our corporate service offers individuals and organisations complete visibility on taxi spend with on-demand automated reporting and as Ireland’s largest and only nationwide network, wait times are as low as 4 minutes.  There’s options available to suit everyone: from enterprise organisations to SME\'s to individuals. </p>';
$message .= '<p><a href="https://www.youtube.com/watch?v=jGDxs9Xf0jA" target="_new"><img src="http://business.mytaxi.ie/youtube.jpg"></a></p>';
$message .= '<p>A member of our corporate team will be touch with you shortly.</p>';
$message .= '<p>Many Thanks, <br>mytaxi | Business Team</p>';
$message .= '</body></html>';
// Sending email
mail($to, $subject, $message, $headers);

它工作正常但后来我被要求用新的联系表格替换

这是新的联系表格:

                        <form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="GET">

                        <input type=hidden name="oid" value="00Db0000000IeRo">
                        <input type=hidden name="retURL" value="http://business.mytaxi.ie/thankyou.php">

                        <input id="email" maxlength="80" name="email" size="20" required="" type="email" value="" oninvalid="InvalidMsg(this);" oninput="InvalidMsg(this);" placeholder="email"/>

                        <input type="hidden" id="lead_source" name="lead_source" value="Web" />

                        <input type="hidden" id="country" name="country" value="Ireland" />

                        <input type="submit" name="submit" value="Register Interest" title="Register Interest" class="bannerbutsub">


                        </form>

正如您所看到的,在新的联系表单中,属性Action =&#34;&#34;中有一个URL。联系表格,以便确认电子邮件不再有效。 我无法取出价值,因为它是必需的。是否有不同的方式来保留新的联系表单并在用户提交CF后继续发送确认电子邮件?

1 个答案:

答案 0 :(得分:0)

理想情况下,现在需要在以下位置处理确认电子邮件的发送:     https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8

有很多方法可以解决这个问题......你可以再次清空动作,然后提交给你的脚本,然后使用curl让你的脚本重新提交数据到     https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8 然后根据回复发送电子邮件。

您还可以在表单提交时向脚本发送ajax请求,您的脚本会在其中处理电子邮件的发送。

但这些都非常苛刻,最终响应/通知用户表单提交成功/失败的工作是表单数据提交给脚本的责任。