[TYPO3-dev] Sending emails and check if the mail was accepted

Stefan Geith typo3dev at geithware.de
Wed Mar 8 17:26:39 CET 2006


Markus Friedrich schrieb:
> Hi!
> 
> I'm writing an extension and I need to send emails. I intended to use "t3lib_htmlmail" to do this, but I can't see a possibility to check if the mail was successfully accepted for delivery.
> 
> Is there a typo3 function for mailing that allows a check?

I always check, if
1) the part before @ only has a-z, A-Z, 0-9, dot and minus:
    if ( preg_match('/^[a-zA-Z0-9\.\-_]+$/',$mailParts[0]) < 1)
      { error ...
2) the part after @ (domain) has
    a) an A-Record in DNS or
    b) an MX-Record in DNS
    if (!checkdnsrr($mailParts[1], 'MX'))
        if (!checkdnsrr($mailParts[1], 'A')) { error ...
This cuts off all misspellings and so reduced the
chance that an email is lost.
But I don't check, whether the email _reaches_ the client...

Here my codesnippet for testing:
<snip>
if (stristr($mailaddress,'<') &&
     strpos($mailaddress,'>')>strpos($mailaddress,'<')) {
     $maildata = substr($mailaddress,strpos($mailaddress,'<')+1,
		strpos($mailaddress,'>')-strpos($mailaddress,'<')-1);
}
$mailParts = explode('@',$mailaddress,2);
$m = Array(
      '###MAILNAME###'=> $mailParts[0],
      '###MAILDOMAIN###'=>$mailParts[1]);
if (!checkdnsrr($mailParts[1], 'MX'))
    if (!checkdnsrr($mailParts[1], 'A')) {
	$errorMode = true;
}
if ( preg_match('/^[a-zA-Z0-9\.\-_]+$/',$mailParts[0]) < 1) {
	$errorMode = true;
}
</snip>

Mayb this helps a little ...

-

Stefan




More information about the TYPO3-dev mailing list