Jump to content
xisto Community
mrdee

A Question About The Php Mail() Function

Recommended Posts

I run PHP 5.2.17 on my laptop (so, a local machine).

In the php.ini file, the functions for mail and smtp say the following (for as far as I know, as i am a PHP novice):

[mail function]; For Win32 only.SMTP = localhostsmtp_port = 25; For Win32 only.;sendmail_from = frankied[at]****music.plus.com; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").;sendmail_path =; Force the addition of the specified parameters to be passed as extra parameters; to the sendmail binary. These parameters will always replace the value of; the 5th parameter to mail(), even in safe mode.;mail.force_extra_parameters =

I don't know what I need to change, also, I changed the original to my own email address (here masked out for security reasons), but that line is still commented.

I also uploaded two scripts, one called mail.php, code below:
<?php$to = "fd******[at]gmail.com";$subject = "Test mail";$message = "Hello! This is a simple email message.";$from = "webbie[at]v****-f******.org.**";$headers = "From:" . $from;mail($to,$subject,$message,$headers);echo "Mail Sent.";?>

Once again, i have masked my email address for security reasons.

and mailform.php, code below:

<html>
<body>
<?phpif (isset($_REQUEST['email']))//if "email" is filled out, send email  {  //send email  $email = $_REQUEST['webbie[at]vl***-f********.org.**'] ;  $subject = $_REQUEST['Proberen'] ;  $message = $_REQUEST['Ratatatatatatatataaaaaaaaaaaaaa'] ;  mail("fde*******[at]gmail.com", "$subject",  $message, "From:" . $email);  echo "Thank you for using our mail form";  }else//if "email" is not filled out, display the form  {  echo "<form method='post' action='mailform.php'>  Email: <input name='email' type='text' /><br />  Subject: <input name='subject' type='text' /><br />  Message:<br />  <textarea name='message' rows='15' cols='40'>  </textarea><br />  <input type='submit' />  </form>";  }?></body></html>

Same here, emails masked for security reasons.

Now, when I run both scripts, not one error is generated, and I get the message the mail has been sent successfully, but no mail ever arrives.

Does anyone know what I am doing wrong and how I can make the mail() function work so I can test scripts locally, scripts that involve sending emails?

Any help will be much appreciated.
Edited by mrdee (see edit history)

Share this post


Link to post
Share on other sites

mrdee we can not test mail functionality through local server, because ISPs have their own policies and have blocked port 25 (SMTP port) at their end. So if you want to test mail local have to use another server like gmail, yahoo etc or of your hosting provider in your script or have to contact your ISP to provide mail service.

Edited by agyat (see edit history)

Share this post


Link to post
Share on other sites

But do I have to do it in my script, or can I set the smtp sever in my php.ini or similar?


You can set it in php.in or use through your script, decision is upto you. php.ini way is simple just to modify two lines.

and if you want it through script, i prefer you to read about mail() syntax and its uses.

Share this post


Link to post
Share on other sites

I have the following in my php.ini:

[mail function]; For Win32 only.SMTP = smtp.o2.co.uksmtp_port = 25

That does not seem to do the trick, though.

Share this post


Link to post
Share on other sites

Thanks again.However, I know all that, I know it is port 25, and I know you have to enter your full emailaddress as username and your password, but the topic you referred me to does not utter a single word about how to implement the last two elements (username and password) into your php.ini file.

Share this post


Link to post
Share on other sites

Ok just find these two lines in php.ini

;auth_username=;auth_password=


and if those are present; remove ";" and set your O2 username and password.

if those are not present add those line without ";" just after smtp port setting.

Another way is by using ini_set() in your script; which not required you to edit php.ini.

ini_set(SMTP, 'Write your SMTP SERVER here');ini_set(smtp_port, 'Write smtp port here ex. 25');ini_set(auth_username, 'Write SMTP SERVER username here');ini_set(auth_password,'Write SMTO SERVER authentication password here');ini_set(mail.log, 'Set path for mail log not necessary but will helpful to sort out errors and problems');

Please if it help you don't forget to vote it up by pressing up green button. :)

Share this post


Link to post
Share on other sites

I have pressed the green button out of gratitude for all your efforts.However, none of the solutions have worked, I'm afraid.Thank you anyway.

Share this post


Link to post
Share on other sites

Ok, any error that you got.can you post your editing or changes here.Ohhh, how stupid i am.it was my silly mistake. Please enclose first argument of ini_set() in '' .Sorry for mistake. And

Edited by agyat (see edit history)

Share this post


Link to post
Share on other sites

No silly mistake, you DID include the '' to include the argument in.

Can't send any errors, couldn't set up a log file.

However, here are the changes I made in my php.ini:

[mail function]; For Win32 only.SMTP = smtp.o2.co.uksmtp_port = 25auth_username="frankie_deschacht@o2.co.uk"auth_password="**********"; For Win32 only.sendmail_from ="frankied@jazzmusic.plus.com"; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").;sendmail_path =

Share this post


Link to post
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...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.