Loading...


bookmark - A Question About The Php Mail() Function

A Question About The Php Mail() Function

 
 Discussion by mrdee with 12 Replies.
 Last Update: February 15, 2012, 2:28 pm
 
bookmark - A Question About The Php Mail() Function  
Quickly Post to A Question About The Php Mail() Function  w/o signup Share Info about A Question About The Php Mail() Function  using Facebook, Twitter etc. email your friend about A Question About The Php Mail() Function Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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):

CODE

[mail function]
; For Win32 only.
SMTP = localhost
smtp_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:

CODE



<?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>

CODE


<?php
if (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.

   Wed Feb 15, 2012    Reply         

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.

   Wed Feb 15, 2012    Reply         

OK, agyat.
Thank you.

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

   Wed Feb 15, 2012    Reply         


QUOTE (mrdee)


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

Link: view Post: 514098


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.

   Wed Feb 15, 2012    Reply         

I have the following in my php.ini:

CODE



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


That does not seem to do the trick, though.

   Wed Feb 15, 2012    Reply         

ok just visit following link
http://forum.o2.co.uk/viewtopic.php?t=173
may help you in this way.

   Wed Feb 15, 2012    Reply         


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.

   Wed Feb 15, 2012    Reply         

Ok just find these two lines in php.ini

CODE

;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.

CODE

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. :)

   Wed Feb 15, 2012    Reply         

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.

   Wed Feb 15, 2012    Reply         

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

   Wed Feb 15, 2012    Reply         

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:

CODE

[mail function]
; For Win32 only.
SMTP = smtp.o2.co.uk
smtp_port = 25
auth_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 =

   Wed Feb 15, 2012    Reply         

Try Swiftmailer or Phpmailer instead of php mail().

   Wed Feb 15, 2012    Reply         

Yes, I might give that a try.

Thank you for all your help. ;)

   Wed Feb 15, 2012    Reply         

Quickly Post to A Question About The Php Mail() Function  w/o signup Share Info about A Question About The Php Mail() Function  using Facebook, Twitter etc. email your friend about A Question About The Php Mail() Function Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

PHP Function To Add Previous and Ne...

CODE<?php function navigationbar($start_number = 0, $items_per_page = 50, $count) { // Creates a navigation bar $current_page = $_SERVER["PHP_SELF"]; if (($start_number < 0) || ( ...more

   22-Jul-2008    Reply         

A Question About Php Mail

I have code my website with send mail feature, I just notice that everytime i send out email, it uses gamma.xisto.com as the sender, but the fact is I want to use my own email account that exist in trap17, suppose I create email account name webmaster@innosia.trap17.com then how exactly can I send a ...more

   11-Sep-2008    Reply         

Php Mail Function Not Working!

Well in this month when I started transforming my unready xhtml files into php and making mail function by POST since I figured out "GET" is an insecure way of transforming information of other people. I got problem, it's in finnish but I have explained the stuff in English in the comm ...more

   01-Dec-2008    Reply         

Using Randomly Generated And Integrating A Retweet/share Button    Using Randomly Generated And Integrating A Retweet/share Button (0) (3) More Advice Needed From Php Experts.   More Advice Needed From Php Experts.