Web Site Creator Web Hosting Help
   Sending Email from your PHP Pages


To send email from your PHP pages, use the following code. The first section is an example of how to send mail from your php page using one of your Web Hosting accounts emails.  In order for this to work properly, you will need to download the "PHPMailer Class" files from SourceForge.  Edit the first section of the file as indicated below:

<?php

$YourEmailAddress = 'email@email.com'; //Email address you want the mail to go to
$Yourname = 'My name'; //Who the email is sent from - this is a name not an email
$MailUsername ='email@email.com'; //Email address you are using to send the email
$MailPassword = 'EmailPassword'; //This is the password of the email account used to send the email
$MailServer = 'smtp.yourdomainname.com'; //Assigned mail server
$MailType = 'HTML'; // Can use HTML or TEXT -case doesn't matter

require("class.phpmailer.php"); //Change this to the real path of the file - this assumes that the mail script
//and the included files are in the same directory


#----------------------- DO NOT EDIT BELOW THIS LINE ------------------------------#

# These are the form Vars - do not edit
$action = $_POST['action'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if(strtolower($MailType) == 'html'){
$mailtypetosend = true;
} else {
$mailtypetosend = false;
}

$mail = new PHPMailer();

$mail->From = $email;
$mail->FromName = $email;
$mail->Host = $MailServer;
$mail->Mailer = "smtp";

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $MailUsername; // SMTP username
$mail->Password = $MailPassword; // SMTP password

$mail->AddAddress($YourEmailAddress, $Yourname);
$mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
$mail->SetLanguage("en", "language/");

//Start the page action upon submittal
if ($action == "contact" ) {
if (empty($_POST['name'])) {
$name = FALSE;
$message .= '<br>Please enter your name</br>';
} else {
$name = $_POST['name'];
}
if (empty($_POST['phone'])) {
$phone = FALSE;
$message .= '<br>Please enter a phone number to reach you at</br>';
} else {
$phone = $_POST['phone'];
}
if (empty($_POST['email'])) {
$email = FALSE;
$message .= '<br>Please enter your email address</br>';
} else {
$email = $_POST['email'];
}
if (empty($_POST['comments'])) {
$comments = FALSE;
$message .= '<br>You did not enter in a message</br>';
} else {
$comments = $_POST['comments'];
}

if($comments && $email && $phone && $name){

$mail->Subject = "Contact Us form submitted";
$mail->Body = "A contact us form has been submitted from the website\nHere are the details:\n\n\n";
$mail->Body .= "Name: $name \n";
$mail->Body .= "Phone number: $phone\n";
$mail->Body .= "Email Address: $email\n";
$mail->Body .= "Message: $comments\n\n\n";

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$sent = 1;
}


echo "<table width=\"622\" border=\"0\" align=\"left\" class=\"table01\">
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Thank you for contacting us, We will respond to all inquiries in the order as they are received, as soon as it is possible.</span></td>
</tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Name: $name</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Email Address: $email</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Phone Number: $phone</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Message: $comments</span></td>
</tr>
<tr>
</table>";
}
}
if(isset($message)) {echo "<left><u><b>$message</span></b></u></left><br>";}

if($sent != 1){
echo "
<table width=\"424\" border=\"0\" align=\"left\" >
<form name=\"form1\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<input type=\"hidden\" name=\"action\" value=\"contact\">
<tr>
<td colspan=\"2\">Contact Form</td>
</tr>
<tr>
<td>Name</td>
<td>
<input name=\"name\" type=\"text\" value=\"$name\">
</td>
</tr>
<tr>
<td>Email Address </td>
<td><input name=\"email\" type=\"text\" value=\"$email\"></td>
</tr>
<tr>
<td>Phone Number </td>
<td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
</tr>
<tr>
<td height=\"86\">Message / Comments </td>
<td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
</td>
</tr>
<tr>
<td height=\"20\" colspan=\"2\"><left><input type=\"submit\" name=\"Submit\" value=\"Submit\"></left></td>
</tr>
</form>
</table>";
}

?>


Sign Up Now! Overview

Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
   is an affiliate of   , a leading domain name services company.
Copyright © 1998-2018 Enom LLC. All rights reserved. Terms & Conditions | Privacy Policy | Abuse Policy