1,105,334 Community Members

Mail() could not send email

Member Avatar
nunuaziz_
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I've been trying to send email using php. But I've been getting this error since...

PHP Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\www\IT3126Prac\Reservation\insertReserve.php on line 36

I know I have to configure something on php.ini. But I don't have the guts to configure it. Any alternatives if I could send email without configuring my php.ini??

Member Avatar
veedeoo
Veteran Poster
1,008 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

Can you tell us what do you have in your server?

  1. Apache?
  2. PHP version?
  3. Mercury mail?
  4. Send Mail?

Those things we need know..

Member Avatar
nunuaziz_
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@veedeoo

I have Apache server... Oh and Im doing it on localhost. For now...

Member Avatar
code739
Posting Whiz in Training
213 posts since May 2012
Reputation Points: 17 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 6 [?]
 
2
 

be sure to run your mail server..

then have this php code

ini_set("SMTP","127.0.0.1");            # set the smtp server
ini_set("smtp_port","25");                # set port
mail($sendTo, $subject, $msg, $header);     #send mail
Member Avatar
veedeoo
Veteran Poster
1,008 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 17 [?]
 
2
 

@nunuaziz_,

try code739 recommendation first.. if it does not do the job.. try...

look inside your server's directory, look for a directory named send mail..and your local server should have a Mercury Mail in it or equivalent.

For Wampp and Xampp this directory is inside the installation dirctory, or the same level as the Apache directory.

Before posting your response, copy, paste to notepad, save as find.php in the htdocs dirctory of your localhost this code

<?php 

phpinfo(); 

?>

Use your browser and point it to http://localhost/find.php ..

Locate "Loaded Configuration file" ... this will tell you which php.ini file is loaded or currently being use by your server.

Using a notepad or any suitable text editor.. open the php.ini file as shown by your phpinfo above.

IMPORTANT!!!! You need to have a gmail account for this work..

on your php.ini file as mentioned above, locate

  [mail function]

find

 SMTP = localhost
smtp_port = 25
sendmail_from = postmaster@localhost

change the above to

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = YourAccountUserName@gmail.com

SAVE YOUR CHANGES.....

Second Step ... find the sendmail This is located or in the same level as the htdocs, apache, mysql, and phpMyAdmin..

Open the sendmail directory and locate the file named sendmail.ini

once again, find

smtp_server=localhost
smtp_port=25
;auth_username=
;auth_password=

change the above to this

;smtp_server=localhost
;smtp_port=25
;auth_username=
;auth_password=

JUst below the commented entries above, addd

smtp_server=smtp.gmail.com
smtp_port=587
auth_username= YourAccountUserName@gmail.com
auth_password= YourGmailAccountPassword

Save your changes on both files...
Re-start your server.. make sure this is done properly..

Test your php script.. it should be able to send email from your localhost using the gmail email account.

If you are on windows, make sure the firewall is not blocking the Mercury Mail or the mail service included in your local server..

I cannot show you how to send from generic mailer and I will never will not teach anyone how to do it, because of potential spammers are lurking all over the Internet.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: