Contact information and email sent by using PHP

Source: Internet
Author: User
Tags valid email address contact form
It is vital to use PHP to establish contact information and send an email to your website in a form of contact, when you need to know what your website visitors think of your website. We will first create a simple three forms of contact ?? -Email address, name, and comment. I will use a table to adjust 3 fields and send button. Create a new file, stick the contact information created using PHP, and send emails.
There is a form of contact on your website that is crucial when you need to know what your website visitors think of your website. We will first create a simple three forms of contact ?? -Email address, name, and comment. I will use a table to adjust 3 fields and send button. Create a new file and paste the code below it. Save it as test. php and upload it to your Web server. Now you have a web (http://www.software8.co) with a simple contact form.

Then, we need the actual PHP code to submit the above form when sending an email. We need to define the email that the message should be sent to ($ ToEmail) or the topic of the message to be sent ($ EmailSubject. Changing the youremail@site.com message should be sent to your email address and your message also adds an appropriate topic. The $ mailheader variable is used to define the mail header. Our goal, from the reply and message content type fields. There are some more usable fields, but in this example, we will only use these three fields. Depending on your server configuration, you may need to have a field that is a valid email address from your server. if you have a domain name mysite.com, you should use a valid email address and other contact information: mysite. COM. In this example, I send an email using the actual email address and submit it on site. Next, all data submitted in the form of a network is saved from the $ _ POST variable in the $ MESSAGE_BODY variable. Using the nl2br feature, you will make all new lines in your comment box also show new production lines in your email. We have all the data required for our email and will use the mail () function to send us an email.


$ ToEmail = 'youremail @ site.com ';

$ EmailSubject = 'site contact form ';

$ Mailheader = "From:". $ _ POST ["email"]. "\ r \ n ";

$ Mailheader. = "Reply-To:". $ _ POST ["email"]. "\ r \ n ";

$ Mailheader. = "Content-type: text/html; charset = ISO-8859-1 \ r \ n ";

$ MESSAGE_BODY = "Name:". $ _ POST ["name"]."
";

$ MESSAGE_BODY. = "Email:". $ _ POST ["email"]."
";

$ MESSAGE_BODY. = "Comment:". nl2br ($ _ POST ["comment"])."
";

Mail ($ ToEmail, $ EmailSubject, $ MESSAGE_BODY, $ mailheader) or die ("Failure ");

?>

What we need to do now is to combine the network form and email sending code to a single page. We will use an if statement to check. if the submitted table is like this, it will send this email to display it on the screen, instead of the message in the Web form "Your email is sent.

If ($ _ POST ["email"] <> ''){

$ ToEmail = 'youremail @ site.com ';

$ EmailSubject = 'site contact form ';

$ Mailheader = "From:". $ _ POST ["email"]. "\ r \ n ";

$ Mailheader. = "Reply-To:". $ _ POST ["email"]. "\ r \ n ";

$ Mailheader. = "Content-type: text/html; charset = ISO-8859-1 \ r \ n ";

$ MESSAGE_BODY = "Name:". $ _ POST ["name"]."
";

$ MESSAGE_BODY. = "Email:". $ _ POST ["email"]."
";

$ MESSAGE_BODY. = "Comment:". nl2br ($ _ POST ["comment"])."
";

Mail ($ ToEmail, $ EmailSubject, $ MESSAGE_BODY, $ mailheader) or die ("Failure ");

?>

Your message was sent


} Else {

?>




};

?>
Industry Portal (www. software8.co) article, I hope you can leave a message for suggestions
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.