Validate an e-mail address
From Joomla! Documentation
(Difference between revisions)
m |
m |
||
| Line 7: | Line 7: | ||
<source lang="php"> | <source lang="php"> | ||
$mail =& JFactory::getMailer(); | $mail =& JFactory::getMailer(); | ||
| − | if ($mail->addRecipient($ | + | if ($mail->addRecipient($mailaddress)->IsError()) echo 'Invalid'; |
</source > | </source > | ||
[[Category:JMail]] [[Category:Developers]] [[Category:CodeExample]] [[Category:MethodExample]] | [[Category:JMail]] [[Category:Developers]] [[Category:CodeExample]] [[Category:MethodExample]] | ||
Latest revision as of 10:59, 21 November 2012
If you want to validate an e-mail address in your code and you will use JMAIL anyway, you can use the function from its parent class phpmailer.
$mail =& JFactory::getMailer(); if (!$mail->ValidateAddress($mailaddress)) echo 'Invalid';
This is implicitly done for every JMAIL function that sets an address (such as addRecipient, addBCC, ..) and though there are other potential errors besides address validating, it most probably is something you want catch too.
$mail =& JFactory::getMailer(); if ($mail->addRecipient($mailaddress)->IsError()) echo 'Invalid';