Jump to content

Email with attachment - message URL not rendering


johnhenry
Go to solution Solved by johnhenry,

Recommended Posts

I have written the following script which sends an email with attachment.  I also want to include a message with a URL, but the URL is not clickable.

 

I have tried it with the message portion containing the URL at the end, as shown, and at the start before '$message = "This is a multi-part message in MIME format.\n\n" .' (I changed that line to $message.= "etc. to concatenate.

 

Is there a way to include a URL that is clickable?

<?php
$url="http://www.mydomain.com";
// Settings
$pdf_name="my_pdf.pdf";
$email = "me@myemail.com";
$to = "$name <$email>";
$from = "admin@myheadoffice.com";
$subject = "Job sheet with attachment";
$fileatt = "admin/pdfs/".$pdf_name;
$fileatttype = "application/pdf";
$fileattname = $pdf_name;
$headers = "From: $from";
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
$message.= "\n\nPDF attached. \n\n".$url;
if(mail($to, $subject, $message, $headers)) {
echo "Successfully sent with attachment";
}
else
{
echo "There was an error sending the mail.";
}
?>



 

Link to comment
Share on other sites

Thanks.  I copied that entire code, made the correction ( took out the dashes ) and substituted my piece of html instead of theirs, as...

$html = '<html><head></head><body><a href='.$url.'>Web page</a></body></html>';

I get the email but no text at all and no URL link.

 

Maybe it didn't work for them either!

 

From my research I think there seem to be many ways of sending an email message with attachment.  My way works except for the URL being plain text. It's not really my way, of course.  I got it from some tutorial.

Link to comment
Share on other sites

  • Solution

I have solved my problem.  I just wanted to thank you for your attempts to help.

 

I have gone in a different direction, using PHPmailer.

 

It is so easy to install and use I cannot understand why I haven't discovered it before.

 

If anyone else has problems mailing I would recommend using it.

 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.