narcis Posted September 10, 2012 Report Share Posted September 10, 2012 Can anyone explain me how to send an e-mail from a web, with php? In Misc > functions: part2 Stefan Explains a bit the mail function. I try and it doesn't work for me. I get Email sent: 1, but I don't receive the email - I attached the file: mail1.php: $did_send = mail('info@mig-marketing.com','Subject','body of the message'); echo "Email sent: " . $did_send; - I tried something more complex. But I don't receive the email either. mail2.php: $to = "info@mig-marketing.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "narcis@mig-marketing.com"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; mail1.php mail2.php Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 10, 2012 Report Share Posted September 10, 2012 Where are you testing the mail() function? On your local computer using WAMP or MAMP? On a live web host? If you are testing on your local computer, mail() tends not to work. It just depends on your setup... and may require you to modify your PHP.ini file to get it to work. I generally recommend testing mail() functionality on a live server rather than on your local computer. Quote Link to comment Share on other sites More sharing options...
narcis Posted September 10, 2012 Author Report Share Posted September 10, 2012 I'm testing these files in a remote server and I don't receive the mail Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 10, 2012 Report Share Posted September 10, 2012 Are you running this on a Linux or Windows based server? I know I have had trouble with running the mail() function on a Godaddy based Windows server, where mail() was disabled. Quote Link to comment Share on other sites More sharing options...
narcis Posted September 11, 2012 Author Report Share Posted September 11, 2012 I'm in a Mac OS Lion (OS X 10.7.4) Quote Link to comment Share on other sites More sharing options...
falkencreative Posted September 11, 2012 Report Share Posted September 11, 2012 I'm in a Mac OS Lion (OS X 10.7.4) I'm not worried about what OS your personal computer you are running, but what operating system your server is running, and whether the mail() function might be disabled. And I'm assuming you've checked your spam box, correct? Quote Link to comment Share on other sites More sharing options...
amy Posted September 17, 2012 Report Share Posted September 17, 2012 Can anyone explain me how to send an e-mail from a web, with php? In Misc > functions: part2 Stefan Explains a bit the mail function. I try and it doesn't work for me. I get Email sent: 1, but I don't receive the email - I attached the file: mail1.php: $did_send = mail('info@mig-marketing.com','Subject','body of the message'); echo "Email sent: " . $did_send; - I tried something more complex. But I don't receive the email either. mail2.php: $to = "info@mig-marketing.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "narcis@mig-marketing.com"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; narcis, try simplifying the process a bit by using this code all by itself in a php page: mail('youremail@gmail.com', 'This is My subject', 'This is the message', null,'-finfo@yourdomain.info'); I've always been able to use that on HostGator and most sites without a problem. I do have one host that disables the php mail function though, so it doesn't work with them. Quote Link to comment Share on other sites More sharing options...
markvs Posted September 17, 2012 Report Share Posted September 17, 2012 Shouldn't you enclose your mail function within an if statement if you want to test if it was accepted to be sent and echo out something whether true or false? e.g. $subject = "testing mail"; $message = "Here is a test mail message"; $to = "me@gmail.com"; $from = "me@gmail.com"; $header = "From: ".$from; if(mail($to, $subject, $message, $header)) echo "Oh ya!<br>"; else echo "well crap!<br>"; Quote Link to comment Share on other sites More sharing options...
amy Posted September 18, 2012 Report Share Posted September 18, 2012 Shouldn't you enclose your mail function within an if statement if you want to test if it was accepted to be sent and echo out something whether true or false? e.g. $subject = "testing mail"; $message = "Here is a test mail message"; $to = "me@gmail.com"; $from = "me@gmail.com"; $header = "From: ".$from; if(mail($to, $subject, $message, $header)) echo "Oh ya!<br>"; else echo "well crap!<br>"; Hi markvs, It's much easier to just use the single line.. and check your email for success. Quote Link to comment Share on other sites More sharing options...
markvs Posted September 18, 2012 Report Share Posted September 18, 2012 Hi markvs, It's much easier to just use the single line.. and check your email for success. Hi Amy, I agree, but by using the if statement, you would at least know if the email was being handed off to the mail server for delivery, whether delivered or not. Quote Link to comment Share on other sites More sharing options...
amy Posted September 18, 2012 Report Share Posted September 18, 2012 Hi Amy, I agree, but by using the if statement, you would at least know if the email was being handed off to the mail server for delivery, whether delivered or not. True true! It's definitely an option! Quote Link to comment Share on other sites More sharing options...
Guest jimcarry28 Posted September 25, 2012 Report Share Posted September 25, 2012 If you are testing on your local computer, mail() tends not to work. It just depends on your setup... and may require you to modify your PHP.ini file to get it to work. I generally recommend testing mail() functionality on a live server rather than on your local computer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.