Jump to content

Email with attachment - message URL not rendering


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 = "[email protected]";
$to = "$name <$email>";
$from = "[email protected]";
$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.";
}
?>



 

I've got to go out now and I can't find the examples I did last night but it was an answer on stackoverflow...

 

Actually it may be answer 2 here:

http://stackoverflow.com/questions/686539/problems-with-sending-a-multipart-alternative-email-with-php

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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.