// recuperation de l'objet mailer
$mailer = JFactory::getMailer();
//recuperation de la configuration
$config = JFactory::getConfig();
// recupertation de la config mailfrom
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' ) );
$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
// si plusieur destinataires
$recipient = array( 'person1@domain.com',
'person2@domain.com',
'person3@domain.com' );
$mailer->addRecipient($recipient);
// creation du mail
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
// Optional file attached
$mailer->addAttachment(JPATH_COMPONENT.DS.'assets'.DS.'document.pdf');
// si mail html
$body = '<h2>Our mail</h2>'
. '<div>A message to our dear readers'
. '<img src="cid:logo_id" alt="logo"/></div>';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
// Optionally add embedded image
$mailer->AddEmbeddedImage( JPATH_COMPONENT.DS.
'assets'.
DS.
'logo128.jpg',
'logo_id',
'logo.jpg',
'base64',
'image/jpeg'
);
//envoie du mail
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
Aucun commentaire:
Enregistrer un commentaire