0

I use mail() to send emails but the output says it is success but i do not received any emails. can someone help me please in using mail()?

function send_mail() {

    $message = 'Please reset your passwrod etc.';

    if (mail('ruedastefano@gmail.com', 'password reset', $message, 'from: bjmpncr@thefourpobu.com')) {

        echo 'success';
    } else {
        echo 'failed';
    }
}  
Shrikant Mavlankar
  • 1,145
  • 1
  • 8
  • 17
Tep Tep
  • 59
  • 3
  • 16
  • Is there any error? – Pradeep Jul 16 '16 at 07:52
  • View your /var/log/mail.log – Quynh Nguyen Jul 16 '16 at 07:56
  • do you send correct headers etc? Else try some php mail library – Medda86 Jul 16 '16 at 08:05
  • Code looks fine. Just to confirm, where you are executing? On your local environment or on Server? – Shrikant Mavlankar Jul 16 '16 at 08:06
  • Gmail may be refusing your e-mail as a result of (spam)filters. The best way to test if your script is working is to send it to an emailaddress other than Gmail. When it does, read about 'SPF' records to ensure your email is not marked as spam. – Jan Willem Jul 16 '16 at 08:11
  • Have you thought about using codeigniter email helper http://www.codeigniter.com/user_guide/helpers/email_helper.html since you have codeigniter tag. –  Jul 16 '16 at 08:18
  • Please have print_r(error_get_last()); after your code so you can catch up the error. It might be something related to your mail server misconfiguration. Or mails are just delayed few minutes. – harisdev Jul 16 '16 at 09:21
  • Please check how to remove captcha or reset captcha from your email account. It has generated some problem while you send email from your email server. – Domain Jul 16 '16 at 09:35

1 Answers1

0

Its because your mail config not set correctly.

Check

  1. Environment(if local check this / if live-host most of time it will config automaticaly)
  2. User Authentication(Username / password)

Sample code

$to = "abdulla@stackoverflow.com";

$subject = 'Place Order From ';
$message = 'My message goes here';

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: ibjmpncr@thefourpobu.com";

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

Requirements for php mail() function

php.net

For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.

w3Schools

For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file.

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85