Skip to content Skip to sidebar Skip to footer

Sending Email From Html Form Using Php

Ive been trying this out the whole day but I cant figure out how to send an email from my html contact form containing the information from the form to my email address. Im new to

Solution 1:

I have a pretty good idea why your code is not working. It happened to me a long time ago. The reason why your code is not working is because :

  • When you pass "from" in headers, php expects an existing email account of your server. For example :$headers = 'From: emailacc@yourserver.com';
  • So first thing you gotta do is create an email account on your server. And then put the From in header to the email address that you've just created.
  • The From field in the $headers is not the From as you think.
  • <?php
  • $email = $_POST["InputEmail"];
  • $subject = $_POST["InputSubject"];
  • $message = "From: ".$email.", ".$_POST["InputMessage"]; // you put the email address from the input form here
  • $headers = 'From: emailacc@yourserver.com'; // here is the email address specified from which u want to send the email.(i.e. your server email address)
  • mail($to, $subject, $message, $headers)
  • ?>

I'm sure this will do the job :)

Solution 2:

Have a shot at this.

I changed you're $header variable around a little bit, so that rather than setting the email as "$email", It'll actually pass through the posted email entered in the form. This apply's to the name too.

I also made it so that you pass the mail function through the parameters of the if statement, rather than setting a new variable.

$headers = "From: " . $name . "<" . $email . ">"; // notice new concatenation

if(mail("myemail@gmail.com", "Contact Form Submission", $message, $headers)){
    // success message
} else {
    // error message
}

Really hope this helps! :)

Post a Comment for "Sending Email From Html Form Using Php"