Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sending an email by itself can be done by using the <code>mail()</code> command</p> <pre><code>mail('to.address@host.com', 'subject', 'message', 'From: from.address@host.com'); </code></pre> <p>The whole code would look something like this:</p> <p>HTML:</p> <pre><code>&lt;form action="slurping.php" method="post"&gt; Your name: &lt;input type="text" name="name" /&gt;&lt;br /&gt; Your email: &lt;input type="text" name="email" /&gt;&lt;br /&gt; Recipient: &lt;input type="text" name="recipient" /&gt;&lt;br /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>PHP (slurp.php):</p> <pre><code>// order of parameters is: to, subject, message body, additional headers mail( $_POST['recipient'], 'You just got slurped', 'You\'ve been slurped by '.$_POST['name'].'. Slurp him/her back by visiting http://slurp.com/', "From: {$_POST['email']}\r\n" ); </code></pre> <p>This will send out an email like it's coming from the senders email address to the recipient. </p> <p>There's a lot missing there, though. What you normally want to include is:</p> <ul> <li>Validation of input on the client side (javascript)</li> <li>Validation of input on the serverside</li> <li>Clear out and handle right encodings etc</li> </ul> <p>If you want to do it properly however, so that a greater percentage of your users actually <em>receive</em> the email, you should use a 3rd party library to send out emails. I recommend <a href="http://phpmailer.worxware.com/" rel="nofollow">PHP Mailer</a> or <a href="http://swiftmailer.org/" rel="nofollow">Swift Mailer</a>.</p> <p>Those libraries provide an easy mechanism for you to include HTML in your emails, attachments, allow for easily connecting to SMTP servers and handle all escaping and encoding issues for you.</p> <p>On top of that they encapsulate everything within an Object oriented approach, so if that's your cup of tea, you'll be happy. Se their websites for more info.</p> <p>It's pretty funny, I wrote a blog post about the very issue of email deliverability (getting through spam filters) etc: <a href="http://arnorhs.com/2011/02/21/delivering-email-with-php/" rel="nofollow">http://arnorhs.com/2011/02/21/delivering-email-with-php/</a> - It might be helpful to you.</p> <p>Cheers</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload