我的电子邮件工作流程有什么问题

时间:2017-04-04 06:45:05

标签: javascript php

无变量的php版本有效。但是变量存在问题,所以问题应该是php文件:

这是正确的吗?

<?php
$name=$_GET['q'];
$content=$_GET['r'];
$to      = 'mail@gmail.com';
$subject = $name;
$message = $content;
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: jcblaub@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

html-form - 问题不应该在这里

<form action="/action_page.php" class="header">
    <label for="fname">Name</label>
    <input type="text" id="fname" name="firstname" placeholder="Name ...">

    <label for="lname">E-Mail</label>
    <input type="text" id="lname" name="lastname" placeholder="E-Mail ...">

    <label for="country">Betreff - Optional</label>
    <select id="country" name="country">
        <option value="usa">-</option>
        <option value="australia">Reservierung</option>
        <option value="canada">Reperatur</option>
        <option value="usa">Fahrrad-Auswahl</option>
    </select>

    <label for="subject">Nachricht</label>
    <textarea id="subject" name="subject" placeholder="Nachricht ..." style="height:200px"></textarea>

    <input type="submit" value="Submit" id="submit">
</form>

我的JS文件 - 问题也不应该在这里

ajax call

function send(str, co) {
    if (str == "") {
        document.getElementById("display").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                alert('Ihre Nachricht wurde verschickt!');
            }
        };
        xmlhttp.open("GET","mail.php?q="+str + "&r=" + co ,true);
        xmlhttp.send();
    }
}

1 个答案:

答案 0 :(得分:0)

在php脚本中尝试以下代码

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);