Knowledgebase
Portal Home > Knowledgebase > PHP 5 > Send mail from PHP
Send mail from PHP
| We do not allow sending emails through anonymous mail() function due to security reasons. Hence, you will need to send email through smtp authentication from your script.
You can consider using the phpmailer script for sending out emails through smtp authentication.
It is available for download at below URL:
http://globushosting.com/downloads/PHPMailer_v5.1.zip
(Note : If you are a shared hosting customer/reseller, you do not need to install the above mailer, it is given only for refrence)
-------- A Simple Example: ------------------------
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "mail.domainname.com"; // specify your domains SMTP server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "emailID@domainname.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->WordWrap = 50; // set word wrap to 50 characters $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name $mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject"; $mail->Body = "This is the HTML message body in bold!"; $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) { echo "Message could not be sent.
"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }
echo "Message has been sent"; ?>
|
Add to Favourites
Print this Article
|
Powered by WHMCompleteSolution