GoDaddy space, PHP, email two ways to send Web Forms

Source: Internet
Author: User
Tags email account

Here is the use of GoDaddy Linux host, Windows host should also be similar, I did not try.


The first way to send mail using PHP's own mail () function

File organization, put 123.html and send.php two files in the same directory


123.html
<! DOCTYPE html>
<body>
<form action= "send.php" method= "POST" >
<input type= "text" name= "name" > Name </input><p/>
<input type= "Submit" value= "OK" > Send mail </input>
</form>
</body>


send.php
<! DOCTYPE html>
<body>
<?php
$to = "[email protected]";
$subject = "Subject";
$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.";
?>
</body>






The second approach, using the Phpmailer open source class

File organization, put 123.html and send.php in the same directory, download Phpmailer and name the Phpmailer folder, and put it in the same directory.

GoDaddy gift Enterprise Mailbox, in the Control Panel to add an email account, easy to complete the following SMTP mailbox account and password.


123.html
<! DOCTYPE html>
<body>
<form action= "send.php" method= "POST" >
<input type= "text" name= "name" > Name </input><p/>
<input type= "Submit" value= "OK" > Send mail </input>
</form>
</body>


send.php
<?php
Header (' content-type:text/html; Charset=utf-8 ');
Require "phpmailer/class.phpmailer.php";
$mail = new Phpmailer;
$mail->issmtp (); Set up mail using SMTP
$mail->host = ' mail.site.com '; Mail server address
$mail->smtpauth = true; Enable SMTP authentication
$mail->charset = "UTF-8"; Set up message encoding
$mail->setlanguage (' zh_cn '); Set Error Chinese Tips
$mail->username = ' [email protected] '; SMTP user name, which is the personal email address
$mail->password = ' 123456 '; SMTP password, which is the personal mailbox password
$mail->smtpsecure = ' TLS '; Set enable encryption, note: The Php_openssl module must be turned on
$mail->priority = 3; Set message Priority 1: High, 3: normal (Default), 5: Low
$mail->from = ' [email protected] '; Sender e-mail address
$mail->fromname = ' sender's name '; Sender Name
$mail->addaddress (' [email protected] '); Add recipient
$mail->confirmreadingto = ' [email protected] '; Add a Send receipt e-mail address, that is, when the recipient opens the message, asks if receipts have occurred
$mail->addbcc (' [email protected] '); Add encrypted send, Mail header will not display the secret send the person information
$mail->wordwrap = 50; Set 50 characters for line wrapping
$mail->addattachment ('/tmp/image.jpg ', ' one pic '); Add multiple Attachments
$mail->ishtml (TRUE); Set the message format to HTML
$mail->subject = ' Here is the theme ';
$mail->body = ' This is the HTML information Body <b>in bold!</b>. Time: ';
$mail->altbody = ' This is the principal in plain text for non-html mail clients ';


if (! $mail->send ()) {
Echo ' Message could not being sent. ';
Echo ' Mailer Error: '. $mail->errorinfo;
Exit
}
Echo ' Message has been sent ';

?>











GoDaddy space, PHP, email two ways to send Web Forms

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.