johnhenry Posted October 24, 2013 Share Posted October 24, 2013 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."; } ?> Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 24, 2013 Share Posted October 24, 2013 ? try changing the content-type after the boundary to html Quote Link to comment Share on other sites More sharing options...
johnhenry Posted October 25, 2013 Author Share Posted October 25, 2013 I tried your suggestion but no luck. Not sure of the syntax. Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 25, 2013 Share Posted October 25, 2013 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 Quote Link to comment Share on other sites More sharing options...
johnhenry Posted October 25, 2013 Author Share Posted October 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
Solution johnhenry Posted October 26, 2013 Author Solution Share Posted October 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.