Programming
php email wamp wampserver
Updated Wed, 24 Aug 2022 09:43:27 GMT

How can I send an email using PHP?


I am using PHP on a website and I want to add emailing functionality.

I have WampServer installed.

How do I send an email using PHP?




Solution

It's possible using PHP's mail() function. Remember the mail function will not work on a local server.

<?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com'       . "\r\n" .
                 'Reply-To: webmaster@example.com' . "\r\n" .
                 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
?>

Reference:





Comments (5)

  • +0 – what if i need to send a email from local server. i mean is there any way to access the nearest mailing server and make it send mail for me. i mean i can find the address of a yahoo mailing server and then i use that server for mailing purposes... is this possible? — Mar 17, 2011 at 05:42  
  • +0 – You need to config SMTP on your local server. Take a look at this similar post, stackoverflow.com/questions/4652566/php-mail-setup-in-xampp — Mar 17, 2011 at 05:48  
  • +0 – Hello @MuthuKumaran if that goes in spam is there any good solution for solving it, please answer. — Dec 02, 2014 at 19:22  
  • +0 – @MuhammadAshikuzzaman You can't solve the spam issue in PHP. Please ask a new question on the appropriate StackExchange site if this is still relevant. — Jul 26, 2015 at 01:58  
  • +0 – How to make sure or verify if this works on my local server? If not possible methods to do so, suggest some alternatives please. thank you. — Aug 22, 2016 at 16:55  


External Links

External links referenced by this document: