Godaddy space, PHP, two methods for sending webpage forms via email

Source: Internet
Author: User
The Godaddy space, PHP, and webmail form use the Godaddy Linux host. The Windows host should be similar. I did not try it.


The first method is to use the mail () function provided by php to send emails.

File Organization: place the 123.html and send. php files in the same directory.


123. html










Send. php



$ To = "lasercoder@foxmail.com ";
$ Subject = "topic ";
$ Message = "Hello! ". $ _ POST [" name "].", This is a simple email message .";
$ From = "coder ";
$ Headers = "From: $ from ";
If (mail ($ to, $ subject, $ message, $ headers ))
Echo "Mail sent .";
Else echo "Mail fail .";
?>






Method 2: Use the phpmailer open-source class

Put 123.html and send. php in the same directory, download phpmailer, name it phpmailer, and put it in the same directory.

Godaddy gives away enterprise mail and adds an email account in the control panel to facilitate entering the SMTP email account and password below.


123. html










Send. php
Header ('content-Type: text/html; Charset = utf-8 ');
Require "phpmailer/class. phpmailer. php ";
$ Mail = new PHPMailer;
$ Mail-> isSMTP (); // you can specify SMTP for an email.
$ Mail-> Host = 'mail .site.com '; // email server address
$ Mail-> SMTPAuth = true; // enable SMTP Authentication
$ Mail-> CharSet = "UTF-8"; // Set the email encoding
$ Mail-> setLanguage ('zh _ cn'); // sets the Chinese prompt for an error.
$ Mail-> Username = 'admin @ site.com '; // SMTP Username, that is, the personal email address
$ Mail-> Password = '000000'; // SMTP Password, that is, the personal email Password
$ Mail-> SMTPSecure = 'tls '; // Set to enable encryption. note: The php_openssl module must be enabled.
$ Mail-> Priority = 3; // Set the mail Priority to 1: high, 3: Normal (default), 5: low
$ Mail-> From = 'someone @ someone.com '; // The sender's email address.
$ Mail-> FromName = 'sender name'; // sender name
$ Mail-> addAddress ('lasercoder @ foxmail.com '); // add recipient
$ Mail-> ConfirmReadingTo = 'someone @ someone.com '; // add the Send receipt email address, that is, when the recipient opens the email, it will ask whether a receipt has occurred
$ Mail-> addBCC ('Someone @ someone.com '); // add a bcc. the Mail Header does not display the BCC information.
$ Mail-> WordWrap = 50; // set to automatically wrap 50 characters
$ Mail-> addAttachment ('/tmp/image.jpg', 'One pic '); // add multiple attachments
$ Mail-> isHTML (true); // you can specify the email format as HTML.
$ Mail-> Subject = 'here is the topic ';
$ Mail-> Body = 'This is the HTML information body In bold!. Time :';
$ Mail-> AltBody = 'This is the subject in plain text for non-HTML mail clients ';


If (! $ Mail-> send ()){
Echo 'message cocould not be sent .';
Echo 'mailer Error: '. $ mail-> ErrorInfo;
Exit;
}
Echo 'Message has been sent ';

?>

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.