Send an email in Joomla! 1.5
Written by Kenneth Crowder   
Sunday, 10 August 2008 13:31

We will be using the sendMail() method inide the JUtility Class.

Let's look at the function itself:

function sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment=null, $replyto=null, $replytoname=null )

We should take a look at each parameter that this function accepts and explain a little further.

$from: This is the the email address that the email will look like it is coming from.
$fromname: This is the name of the person or organization this email is coming from.
$recipient: This is the email address (or array of email addresses) that the email will be going to.
$subject: This is the Subject of the email.
$body: The is the message body of the email.
$mode: Set this to 1 for HTML email, set it to 0 for text email. This field is optional.
$cc: This is the email address (or array of email addresses) that the email will be Carbon Copied to. This field is optional.
$bcc: This is the email address (or array of email addresses) that the email will be Blind Carbon Copied to. This field is optional.
$attachment: This is the full path and filename (or array of full paths and filenames) of the files that you wish to attach to the email. This field is optional.
$replyto: This is the the email address that the email will go to if the recipient clicks reply. This field is optional.
$replytoname: This is the name of the person or organization this email will go to if the recipient clicks reply. This field is optional.

Now that you know how that works, let's look at an example!

$from = 'admin@somewhere.com';
$fromname = 'BIGSHOT Blog';
$recipient[] = 'john@somewhere.com';
$recipient[] = 'jane@somewhere.com';
$subject = 'Want to learn about BIGSHOT Blog';
$body = '<p>Check us out!</p><p><a href="http://www.somewhere.com" target="_blank">http://www.somewhere.com</a></p>';
$mode = 1;
$cc = 'bob@somewhereelse.com';
$bcc[] = 'simon@somewhereelse.com';
$bcc[] = 'nick@somewhereelse.com';
$attachment[] = '/home/my_site/public_html/images/stories/food/coffee.jpg';
$attachment[] = '/home/my_site/public_html/images/stories/food/milk.jpg';
$replyto = 'no_reply@somewhere.com';
$replytoname = 'NO REPLY - BIGSHOT Blog';

JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);

Believe it or not kids, that's it!

 

MORE INFO:

sendMail()
http://api.joomla.org/Joomla-Framework/Utilities/JUtility.html#sendMail

Kenneth Crowder has been involved in the Joomla! Community since the days of Mambo. He has volunteered many hours to help out the Open Source Project. He is considered an expert in all things related to Joomla!. He was a Technical Reviewer for Joomla! A Users Guide, as well as another book currently in the editing phase. Learn more about Ken.

Trackback(0)
Comments (1)add comment

Nuno said:

Parece-me muito bem!

[Portuguese translation: "It seems to me very well" - Kenneth]
 
report abuse
vote down
vote up
December 23, 2008
Votes: +0

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security image
Write the displayed characters


busy