0

I have a problem with sending the form to my e-mail. Currently, when i send the form i get message from "emailtest@test.com" with $message2 but i don't get $message from 'inputEmail' to my e-mail "emailtest@test.com".

I would add that I am not PHP programmer and this is my first script in this language.

I would be very grateful for your help

 <?php 
    $to = 'emailtest@test.com'; // 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'); 
?>
osk222
  • 1
  • 1

1 Answers1

0

Since your code works in a local environment, with mailtodisk, I suspect a "problem" with the mail server. You are setting the From: Header of the first email send attempt to the email address of the person that filled out the form. Most mail servers might reject that because it is not a valid address that you own. I am not an expert to this so someone might have a better, more detailed explanation.

Remove the headers from the first email or set the From: Header to a address which can actually sent over that mailserver. If this works you can use a Reply-to header which enables most clients to directly answer to the set email address.

Example below:

...

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

...

I might suggest - even it it looks complicated at first - to use PHPMailer. It makes sending emails with PHP much easier.

Philipp Palmtag
  • 1,310
  • 2
  • 16
  • 18