I am working on my php to fetch the email data using imap. I want to add the <a href ="">
for the domain and <a href="mailto:""
for the email so the hyperlink would display in the email.
Example:
This message was created automatically by mail delivery software.
A message that you sent has not yet been delivered to one or more of its
recipients after more than 72 hours on the queue on <a href="http://server.example.com">server.example.com</a>.
The message identifier is: somerandomid
The subject of the message is: test
The date of the message is: Sun, 24 Mar 2019 20:37:06 +0000
The address to which the message has not yet been delivered is:
<a href="mailto:http://subdomain.example.com">subdomain.example.com" target="_blank">failedemail@example.com</a>
No action is required on your part. Delivery attempts will continue for
some time, and this warning may be repeated at intervals if the message
remains undelivered. Eventually the mail delivery software will give up,
and when that happens, the message will be returned to you.
Here is my output:
This message was created automatically by mail delivery software.
A message that you sent has not yet been delivered to one or more of its
recipients after more than 72 hours on the queue on subdomain.example.com.
The message identifier is: somerandomid
The subject of the message is: test
The date of the message is: Sun, 24 Mar 2019 20:37:06 +0000
The address to which the message has not yet been delivered is:
failedemail@example.com
No action is required on your part. Delivery attempts will continue for
some time, and this warning may be repeated at intervals if the message
remains undelivered. Eventually the mail delivery software will give up,
and when that happens, the message will be returned to you.
When I tried this:
$body = imap_body($inbox, $email_number, 2);
$email_body = utf8_decode(imap_utf8($body));
$failed_email = getBetween($email_body, 'delivered is:', 'No action');
$message = getBetween($email_body, 'us-ascii', 'returned to you.');
$message = nl2br($message);
$pattern = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.';
$pattern .= '[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i';
$replacement = '<a href="mailto:\\1" target="_blank">\\1</a>';
$message = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '<a href="http://$1">$1</a>', $message);
echo $message;
It will show the output like this:
This message was created automatically by mail delivery software.<br />
A message that you sent has not yet been delivered to one or more of its<br />
recipients after more than 72 hours on the queue on <a href="http://subdomain.example.com">subdomain.example.com</a>.<br />
<br />
The message identifier is: someid<br />
The date of the message is: Sun, 21 Apr 2019 18:24:43 +0100<br />
The subject of the message is: Test<br />
<br />
The address to which the message has not yet been delivered is:<br />
<br />
failedemail@<a href="http://example.com">example.com</a><br />
<br />
No action is required on your part. Delivery attempts will continue for<br />
some time, and this warning may be repeated at intervals if the message<br />
remains undelivered. Eventually the mail delivery software will give up,<br />
and when that happens, the message will be
Here is what I want to achieve:
This message was created automatically by mail delivery software.<br />
A message that you sent has not yet been delivered to one or more of its<br />
recipients after more than 72 hours on the queue on <a href="http://subdomain.example.com" target="_blank">subdomain.example.com</a>.<br />
<br />
The message identifier is: someid<br />
The date of the message is: Sun, 21 Apr 2019 18:24:43 +0100<br />
The subject of the message is: Test<br />
<br />
The address to which the message has not yet been delivered is:<br />
<br />
<a href=mailto"failedemail@example.com" target="_blank">failedemail@example.com</a><br />
<br />
No action is required on your part. Delivery attempts will continue for<br />
some time, and this warning may be repeated at intervals if the message<br />
remains undelivered. Eventually the mail delivery software will give up,<br />
and when that happens, the message will be
Can you please show me an example how I could add the href link <a href="domaingoeshere" target="_blank"
for the domain subdomain.example.com
and how i could also add href=mailto"emailgoeshere" target="_blank"
for the email?
Thank you.