Jump to content

PHP's mail() function


atar.yosef

Recommended Posts

Hi there!! I have copied and changed the following code snippet from the php.net site:

<?php$to	  = 'myusername@mydomain.com';$subject = 'the subject';$message = 'hello';$headers = 'From: webmaster@example.com\r\n';if(mail($to, $subject, $message, $headers)){ echo "Success!!"; }?>

unfortunately, my script wasn't executed and I didn't receive the email even in my junk folder. Can someone help me solve this trouble? Thanks in advance!! atar.

Edited by atar
Link to comment
Share on other sites

just because it is on php.net, doesn't mean it is ready to go, copy and paste code. Do you have an SMTP server installed on your host?

  • Like 1
Link to comment
Share on other sites

@thescientist:Thanks for replying!!When I look in the output of the phpinfo() method, I see that there's a row which in its first column it reads "SMTP" and in its second column it reads "localhost". Is that okay? How can I achieve more info if there's in my host a SMTP server?Thanks in advance!!Atar.

Link to comment
Share on other sites

heyy ur code is perfect.. but in case if u want to send mail from localhost server. then u must need to do some settings of your SMTP server in php.ini file. but if u are going to upload your code Live on your site. this will really gonna work..still if u want to run mail() function from localhost i think u must refer this 1) http://www.phpgeniou...your-localhost/ 2) http://rajeshstutori...-localhost.html i haven't tried since simple mail function will work on live site so u try.. hope this will help u ;)

  • Like 1
Link to comment
Share on other sites

@satishpoul:Unfortunately, the solutions suggested at the sites you've referred me to aren't related to me since I use at Linux based server and those solutions are about windows based servers.However, thanks for your attempt to help me!Sincerely!Atar.

Link to comment
Share on other sites

are you using localhost or 3rd party web server? if it is localhost you will need to install sendmail like mail server and set the setting in php.ini "SMTP" to point to sendmail executable binary file path. If it is 3rd party server it is probably already installed, in that case contacting your server admin would be the best option.

  • Like 2
Link to comment
Share on other sites

Thanks to all the members which making effort to help me with this problem!!@birbal:I use at 3rd server. Probably they want some fee in order to allow me using their SMTP server.@westman:I tried your advice. Unfortunately, this didn't solve the problem.Thanks to all!Atar.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...