将变量HTML表单传递到电子邮件表单(javascript,PHP)

时间:2017-09-09 09:49:54

标签: javascript php html

网站:sms.ledeclick.org

它已经起作用,但截至目前尚未正常工作。

左侧表单正确发送短信;

第一个字段是电话号码变量,用于将短信发送到javascript

第二个字段是汽车品牌字段,用于填充短信文本中的变量(个性化)

最终,我需要第二种形式是透明的,甚至在某些时候是不合适的,我唯一需要的是在发送短信之后收到一封电子邮件到我的地址。按下按钮包含:

时间;日期;汽车品牌;电话号码;短信。

将电话号码变量作为电子邮件标题

现在,我只想填充一个变量' inputname2'进入电子邮件,它有点工作'但是'变量字段'在电子邮件中保持空白

左边的形式& html&的javascript:

 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8" />
 <meta name="author" content="Jean-Philippe Théroux" />
 <meta name="description" content="Le Déclick OBNL (c) 2017" />

 <title>Donations d'autos - Envoi de SMS automatisés</title>
 </head>
 <script type="text/javascript" src="jquery-1.8.3.min.js"></script> 
 <body>
 <input type="text" id="userInput0" autofocus value = "" />
 <input type="text" id="userInput2" autofocus value = "" />
 <input type="submit" value="ENVOYER LE SMS" onclick="sendOutput();" /> 
 <script type="text/javascript">
    function sendOutput() {
    var accent = "'"            
    var inputtel = document.getElementById("userInput0").value;
    var inputname2 = document.getElementById("userInput2").value;
        var xhr1 = new XMLHttpRequest();
        xhr1.open('POST', 'https://platform.clickatell.com/messages', true);
        xhr1.setRequestHeader('Content-Type', 'application/json');
        xhr1.setRequestHeader('Authorization', 'bE7pWH27T2uy3RME5QXc8Q==');

        xhr1.onreadystatechange = function () {
            if (xhr1.readyState === 4 && xhr1.status === 200) {
                console.log('success');
            }
        };


 var data1 = JSON.stringify({
        'content': 'Objet: Votre véhicule à vendre sur Kijiji; Bonjour à vous, Le Déclick est un organisme de bienfaisance fondé en 2004 et dûment enregistré à l' + accent + 'ARC (860458835RR0001).  Nous souhaiterions faire l' + accent + 'acquisition de votre ' + inputname2 + ' en vous offrant, plutôt que de l' + accent+ 'argent, un reçu pour fin d' + accent + 'impôt donnant droit à un crédit remboursable de 52,8%. Nous utilisons comme évaluateur externe le Canadian Black Book.  Si vous le souhaitez nous pourrons, en quelques minutes, établir le montant du reçu. Merci d l' + accent + 'intérêt que vous porterez à cette offre pour un bonne cause, André Émond, Fondateur du Déclick, andre.emond@hotmail.com 514-943-7236', 
        'to': ['1' + inputtel+ ''], 'from': '1 450-868-1737'}
        );

xhr1.send(data1);


        alert("MESSAGE SMS ENVOYÉ!");
 function myJavascriptFunction() { 
 var javascriptVariable = "' + inputname2 +'";
 window.location.href = "send_form_email.php?name=" +           javascriptVariable; 
}

 alert ("working");


 return;

}

</script>   
</body>
</html>

正确的表格html:

<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input  type="text" id="firstname" name="first_name" maxlength="50" size="30 autofocus value = """>
</td> 
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input  type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input  type="text" name="email" maxlength="80" size="30">
</td>
</tr> 
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input  type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea  name="comments" maxlength="1000" cols="25" rows="6">             </textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">   <a     href="http://www.freecontactform.com/email_form.php">Email Form</a>
</td>
</tr>
</table>
</form>

PHP FILE(send_form_email.php):

<?php
if(isset($_POST['email'])) {

$inputname2 =  $_GET["imputname2"];

// E-Mail To:
$email_to = "theroux.jobs@gmail.com";
$email_subject = "MikeLovdal.com Form Feedback";


function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the    form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be         valid.<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!eregi($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($inputname2)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n". 
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
 @mail($email_to, $email_subject, $email_message, $headers);  
 ?>

 <!-- include your own success html here -->

 Thank you for contacting us. We will be in touch with you very soon.

 <? 
 }
 ?>

收到的电子邮件:

fou@fou.com通过c-panel2.cyberlogic.net 上午4:38(46分钟前)

对我来说 表格详情如下。

名字:(变量就在这里让我们说出来) 姓氏:他 电子邮件:fou@fou.com 电话:123-333-3333 评论:ohohohoh

0 个答案:

没有答案