How do I send email using PHP?

Windows Hosting Accounts

HostBreak SMTP servers require SMTP authentication therefore your code should be using SMTP AUTH method for sending emails. Therefore to send emails using PHP, you will be using PHPMailer library.

To send emails using PHP, follow these steps:

1. Create an email account, for example script-mailer@mydomain.com where mydomain.com is your domain hosted with us.

2. Modify your PHP script to use PHPMailer class and SMTP authentication. Sample scriipt is provided here.

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // set mailer to use SMTP
$mail->Host = "smtp1.example.com;smtp2.example.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "script-mailer@domain.com";  // SMTP username
$mail->Password = "secret"; // SMTP password

$mail->From = "from@example.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@example.net", "Josh Adams");
$mail->AddAddress("ellen@example.com");                  // name is optional
$mail->AddReplyTo("info@example.com", "Information");

$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

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

Was this answer helpful?

 Print this Article

Also Read

What is domain Redemption Period Status?

The Redemption Period is a 30 day, Registry-imposed hold period. Domains reach the REDEMPTION...

Reseller Getting Started - Linux (WHM/cPanel)

Welcome to HostBreak.com! We are glad you joined our happy customers family, thank you.Getting...

Domain Name LifeCycle

AvailableThe first step is to register a domain name. You need to choose a domain name and if...

Cannot receive emails using Outlook / Email Client

There are several common reasons for not being able to receive emails through Outlook (or other...

Setting up Email Accounts in Parallels Plesk Panel

You can use Parallels Plesk Panel to set up POP3 email accounts for your domain. Log in to...

Powered by WHMCompleteSolution