The mail object is a wrapper for PHPMailer. The various convenience methods makes using PHPMailer easier to remember and more consistent. Let’s begin by creating the Mail object, which is prepared with the UTF-8 charset.

$mail = $this->mail();

Sender and recipients

The wrapper methods generally use the form: ( mandatory parameter, optional parameter ).

$mail->from( '' );
$mail->from( '', 'Optional Name Of Sender' );

Send it to someone.

$mail->to( '' );
$mail->to( '', 'Optional Name of Recipient' );

cc(), bcc(), reply_to() work the same way as to().

Subject and content

$mail->subject( 'This is a great subject' );
$mail->subject( 'This is a %s subject', 'greater' );

Content can be specified as just text or HTML.

$mail->text( 'This is a text message.' );
$mail->text( 'This is %s a text message.', 'also' );

$mail->text( '<p>This is an HTML message.</p>' );
$mail->text( '<p>This is %s an HTML message.</p>', 'also' );


Following the above form:

$mail->attachment( '/tmp/the_file' );
$mail->attachment( '/tmp/the_file', 'Great file.txt' );

Send the message


Did it get sent correctly?

if ( $mail->send_ok() )
echo 'sent';


Leave a Reply

Your email address will not be published. Required fields are marked *