Send Mail Using Amazon Cloud Server With PHP SMTP

In this tutorial i will describe how to send mail using amazon server with PHP SMTP.The amazon cloud server does not allow PHP mail() function to send mail, so that your mail does not work on amazon cloud server. The amazon are providing PHP SDK for PHP mail. We will use php SMTP mailer class to send mail using SMTP.You can also send mail using GMAIL SMTP service.

Before use below code, you should be known about your SMTP user and password, because to configure SMTP we need SMTP user name and password.

You can also check other tutorial of php mail,

Configuration Parameters to send mail with PHP SMTP

You will need to configure the following variables to send mail using PHP SMTP:

  • $from : The email address from which you want the message to be sent.
  • $to/$address : The recipient’s email address.
  • $subject : The subject of mail
  • $body : The body of mail message.
  • $host : SMTP server name.
  • $username : the SMTP user name
  • $password : the SMTP user password

Sample code and Example to send mail with PHP SMTP

require 'class.phpmailer.php';

		$messageBody = "hello!";
		$from = 'from mail id';
		$mail = new PHPMailer();
		$mail->SMTPDebug = 2;
		$mail->IsSMTP(true); // SMTP
		$mail->SMTPAuth   = true;  // SMTP authentication
		$mail->Mailer = "smtp";
		$mail->Host       = ""; // Amazon SES server, note  protocol
		$mail->Port       = 465;                    // set the SMTP port
		$mail->Username   = "";  // SES SMTP  username
		$mail->Password   = "";  // SES SMTP password
		$mail->SetFrom($from, 'from email id');
		$mail->Subject = "test smtp";
		$address = 'tomail';
		$mail->AddAddress($address, 'tomail');
			$isSend= $mail->Send();
		if (!$isSend)
		     die('Sorry, message delivery failed. Contact webmaster for more info.');
		}catch (Exception $e){
			echo $e->getMessage();die;

You can change configuration variable as per your need and use it.I hope you enjoyed sending mail with PHP SMPT on amazon cloud server.

Download script