1

I am using Laravel and i would like to use php mail function. I have tried this:

$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <info@address.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail('myaddress@gmail.com', 'My Subject', 'test', $headers);

but no email get's sent atleast I do not recieve it checked spam folder and it's not there and I do not recieve any error message when this code is executed.

what does php mail function use to send mail? Maybe I missed configuring something?

Also I am not running this localy, I have it uploaded to my VPS which runs Ubuntu 16.04.1 LTS

niko craft
  • 2,893
  • 5
  • 38
  • 67
  • Does your Ubuntu have a mail server configured? – Cagy79 Nov 24 '16 at 13:21
  • Try a var_dump of the mail() function to check the return value: ` Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.` – Cagy79 Nov 24 '16 at 13:22
  • not that I am aware of, I haven't installed anything my self. I am wondering about php mail function which Wordpress it self uses by default, does it need a mail server for it to work? How does it work on shared hosting? – niko craft Nov 24 '16 at 13:23
  • Check the php mail() manual, it delivers the e-mail message to the system, but php does not send the mail itself. – Cagy79 Nov 24 '16 at 13:24
  • var_dump bool(false) so I need to have mail server configured for php mail function to actually work? – niko craft Nov 24 '16 at 13:28
  • Possible duplicate of: http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail – Cagy79 Nov 24 '16 at 13:29
  • Yes, you need a mail server configured.... – Cagy79 Nov 24 '16 at 13:29

2 Answers2

1

if I was you, then I would try to check the error first, then debug like:

Make sure error reporting is enabled and set to report all errors

error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");



$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <info@address.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";    

$status = mail('myaddress@gmail.com', 'My Subject', 'test', $headers);

if($status)
{ 
  echo '<p>Your mail has been sent!</p>';
 } else { 
 echo '<p>Something went wrong, Please try again!</p>'; 
}
Ruhul Amin
  • 1,751
  • 15
  • 18
0

May be this is because of .env file options overrides your config/mail.php option. Remove these all duplicate options from .env and also check the mail driver 'MAIL_DRIVER' at .env. It should be MAIL_DRIVER=smtp.

Answer reference

Community
  • 1
  • 1
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57