Corona SDK and other Game Development Tutorials

Sending Emails with Attachments using PHP

Recently, I’ve had to set up a cron job send out emails, but the catch was the email needed to have an attachment. There are several ways to send out an email with an attachment using php, but the easiest way I found (so far) was using the file class.phpmailer.php. The class can be found at and once your incorporate this class, send emails with attachments becomes a breeze.

Below is the sample code provided by the developer of PHPMailer, with some few modifications. Remember, you have to have the file class.phpmailer.php in order for this to work properly.


	//Set who the message is to be sent from
	$mail->SetFrom('', 'Daniel');

	//Set who the message is to be sent to
	$mail->AddAddress('', 'Daniel');	

	//Set the subject line
	$mail->Subject = 'Subject Line';

	//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body

Some HTML Tags

Body of the email

', dirname(__FILE__)); //Replace the plain text body with one created manually $mail->AltBody = 'This is the plain text portion of the email.'; //Attach an image file $mail->AddAttachment(''); //Send the message, check for errors if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?>
  1. Thanks?

  2. Thanks

Leave a Reply