0

I have a php script that has taken user input from a html page and created a list. I want to be able to email that list to the user, and already have the user's email address from the html page.

So far, when the user hits 'email me the list' I can get the program to automatically open the person's outlook program. I want to be able to copy and paste the list into the email document, or at least copy and paste the link to the page where the list exists.

Any help would be appreciated.

Thanks

Andrew

EDIT:

HTML FORM:

 <strong>Email Address</strong><FONT COLOR="#FF0000">*</FONT>:
    <input type="text" name="emailaddress2"/> 
  <input type="submit" value="Submit"/>

PHP :

//THE LIST I NEED TO SEND, AND THE EMAIL FUNCTION




$FoodList=array_unique($FoodList);
if(!empty($FoodList))
{
   foreach ($FoodList as $key => $value)
   {
      echo "<li>" . $value . "</li>";
   }
   echo "</ul>";
}



<a href="mailto:<?php echo $_POST['emailaddress']; ?>">Email me List</a> 

(So basically I want the list pasted into the email)

Andrew Smith
  • 310
  • 3
  • 6
  • 19

1 Answers1

2

As mentioned above, the built in PHP mail functionality is a better solution for this -- no need to interface with the external client.

However, you can create a mailto: element with the list as the body by adding an '&body=' part to the link (you can also add '&subject=' etc), something like this:

 <a href="mailto:<?php echo $_POST['emailaddress']; ?>&subject=List&body=List1%0AList2>
 Email me List
 </a> 

If the list is multiline you'll probably need to do something like this (assuming it's an array):

 implode($list, "%0A");

Or you might want to look at using urlencode() the list depending what other chars it has in it.

Note, some mail clients might handle this differently from others, which is why sending the mail directly from PHP is a better option the example from the link in jboneca's comment should be enough to get you started.

Edited to add a second note in response to your edit: If you want to embed HTML in the mail message you'll need to use the PHP mailer as it's not possible via mailto links -- see this answer: MailTo with HTML body

Community
  • 1
  • 1
SpaceDog
  • 3,249
  • 1
  • 17
  • 25