Sending email from html form using php

Noob_Programmer

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 php.

Ive tried running this by uploading it to free web hosting. I get the message "success!" when I press the submit button on my html form but no email is actually sent.

Any help is appreciated.

PHP script:

<?php

//Subject
$subject ="Contact Form Submission";

// Name
$name =$_POST['InputName'];

// Message
$message =$_POST['InputMessage'];

//Mail of Sender
$email =$_POST['InputEmail'];

//From
$header = "From:$name<$email>";

$send_contact=mail("[email protected]",$subject,$message,$header);

//Check if mail was sent
if($send_contact){
echo "Success!";
}
else {
echo "Error!";
}
?>

EDIT: Figured it out after one whole day of trial and error. The problem was with the free web host I was using. Changed hosts and the code started working fine. Hope this helps someone in the future. Thanks all for the help.

The SuperKat

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: [email protected]';
  • 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: [email protected]'; // 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 :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sending an email using HTML form

From Dev

Sending a php email with an attachment from a html form file upload

From Dev

Sending html received from form to email securely with php

From Dev

sending an email from HTML form, address in SQL

From Dev

sending an email using a form (ajax, jquery and PHP)

From Dev

PHP - Sending email from form with mail function

From Dev

php not sending email from contact form

From Dev

Sending an Email from Form using Codeigniter

From Dev

PHP email form not sending email

From Dev

issues/errors with from php form for sending email via local host Xampp using php-mailer library

From Dev

HTML form not sending data to MySQL using PHP

From Dev

sending my form data HTML to an email using SMTP server

From Dev

php contact form not sending email

From Dev

Why is PHP form not sending email

From Dev

php form post not sending email

From Dev

PHP form sending blank email

From Dev

PHP: Getting the email from a form and sending it when a button is clicked

From Dev

html form email php "From" formation

From Java

Sending HTML email using Python

From Dev

Sending email in PHP using AJAX

From Dev

Email sending in php using jquery

From Dev

Sending html Form data to sender's email

From Dev

PHP form isn't sending email to recipients

From Dev

PHP contact form with JS validation not sending email

From Dev

Sending form data as table formatted email in PHP

From Dev

Email form not sending email

From Dev

send an email from a html webpage using php

From Dev

Sending email with an attachment from the form not working

From Dev

Issue sending html email with images in php

Related Related

HotTag

Archive