2016-09-22 28 views
0

将表单发送至我的电子邮件时出现问题。 目前,当我发送表单时,我用$ message2从“[email protected]”得到了消息,但是我没有从'inputEmail'得到$ message到我的电子邮件“[email protected]”。PHP - 将表单发送至电子邮件

我想补充一点,我不是PHP程序员,这是我的第一个使用这种语言的脚本。

我会是你的帮助

<?php 
    $to = '[email protected]'; // this is your Email address 
    $from = $_POST['inputEmail']; // this is the sender's Email address 
    $first_name = $_POST['inputName']; 
    $inputCompany = $_POST['inputCompany']; 
    $inputPosition = $_POST['inputPosition']; 
    $inputProjects = $_POST['inputProjects']; 
    $inputOfficeProjects = $_POST['inputOfficeProjects']; 
    $inputPresentation = $_POST['inputPresentation']; 
    $inputMessage = $_POST['inputMessage']; 
    $number = $_POST['number']; 
    $subject = "Test"; 
    $subject2 = "Test1"; 
    $message = $first_name . " example " . $inputPosition . " wrote the following:" . "\n\n" . $_POST['message']; 
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message']; 
    $headers = "From:" . $from; 
    $headers2 = "From:" . $to; 
    mail($to,$subject,$message,$headers); 
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
    // echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly."; 
    header('Location: dziekujemy.html'); 
?> 

回答

0

因为你的代码在本地环境中工作,与mailtodisk非常感谢,我怀疑一个“问题”与邮件服务器。您将From:首个电子邮件发送尝试的标题设置为填写表单的人员的电子邮件地址。大多数邮件服务器可能会拒绝,因为它不是您拥有的有效地址。我不是这方面的专家,所以有人可能会有更好,更详细的解释。

从第一封电子邮件中删除标题或将From:标题设置为可通过该邮件服务器实际发送的地址。如果这可行,您可以使用一个Reply-to标题,使大多数客户能够直接回复设置的电子邮件地址。下面

例子:

... 

$headers = 'From: ' . $to . "\r\n" . 
    'Reply-To: '.$from; 

... 

我可能会建议 - 即使它看起来比较复杂,在第一 - 使用PHPMailer。它使得使用PHP发送电子邮件变得更容易。