-4

I never been exposed to any learning about sending email in PHP. Could someone just give me the outline/guide me what to do step by step ?

I just want to know the very first step of doing it. I've google, but so far, they just provide the code for mailing without telling where to put the code, or how to start.

user2687998
  • 11
  • 1
  • 1
  • 1
    maybe start with the basics, there are plenty of guides out there to build your knowledge up from the beginning. If someone gives you the code but you dont understand it then its not much use to you – mdoran3844 Aug 19 '13 at 00:43
  • PHP sends mail through the `mail` function, which unfortunately is pretty low-level (you more or less have to manually implement SMTP and feed the results to `mail`). For this reason pretty much everyone uses some ready-made mail library to send email -- unless your needs are very basic it's just not worth the time to do things manually. – Jon Aug 19 '13 at 00:47

2 Answers2

1

It's pretty simple. Just use the mail function:

// Mail information
$to         = 'example@example.com';
$subject    = 'Subject';
$message    .= 'Content of the message.';

// Headers
$headers    = 'MIME-Version: 1.0' . "\r\n";
$headers    .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers    .= 'To: ' . $to . '<' . $to . '>' . "\r\n";
$headers    .= 'From: You <you@example.com>' . "\r\n";

// Actually send the email
mail($to, $subject, $message, $headers);

You'll need to set up a local SMTP server to send it, or your hosting should have one.

federico-t
  • 12,014
  • 19
  • 67
  • 111
1

Look at this : PHP Mail Function

 // To
$to = 'truc@server.com';

// Subject
$subject = 'example- Test Mail';

// Message
$msg = ' - Message of mail ...';

// Headers
$headers = 'From: xxx yyyyy <mail@server.com>'."\r\n";
$headers .= 'Bcc: me <me@server.com>; him <him@server2.com>'."\r\n";
$headers .= "\r\n";

// Function mail()

mail($to, $subject, $msg, $headers);

This will work only if SMTP is configured in your web host or you will need to use gmail,yahoo or any other free SMTP server. Look at this topic Send email using the GMail SMTP server from a PHP page

Community
  • 1
  • 1
Charaf JRA
  • 8,249
  • 1
  • 34
  • 44