How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask abhi_iitian Your Own Question

abhi_iitian
abhi_iitian, Computer Software Engineer
Category: Programming
Satisfied Customers: 1757
Experience:  B-Tech Topper in CSE from IIT Roorkee, Experience as S/W design Engineer at Microsoft India
16530347
Type Your Programming Question Here...
abhi_iitian is online now
A new question is answered every 9 seconds

Warning mail() [function.mail] Failed to connect to mailserver at localh

Customer Question

I need to know the difference between use phpmailer or mail() function in PHP .I tried both , but I got confused now. if I use phpmailer I don't know php.ini works with it.
Submitted: 5 years ago.
Category: Programming
Expert:  abhi_iitian replied 5 years ago.
Hi there,

Could you explain the situation a bit ? What are you trying to achieve.. are you tryinng to make a form so that when submitted , information is sent to your email at a website ?

Abhi
Customer: replied 5 years ago.

So...I have installed wampserver in my computer, so I'm trying t send a email contact form en PHP to any other email company like gmail or yahoo,I'm working in dreamweaver but I don't know exactly how to do this because I got that message.I tried with Phpmailer , :

<?php

/* Subject and Email Variables */

$emailSubject = 'EmailMe!';
$webMaster = 'XXXXX@XXXXXX.XXX';

/* Gathering Data Varibles */

$nameField = $_POST['name'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$commentsField = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Phone Number: $phoneField <br>
Comments: $commentsField <br>
EOD;


$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailsubject, $body, $headers);



/* Results rendered as HTML */

$theResults = <<<EOD

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title></head>

<body> [
background-color: #f1f1f1;
font-family: Verdana, Arial,
Helvetica,sans-serif:
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
]
-->
<style>
<head>

<div>
<div align="left">Thank you for your interest your email will be answer very soon</div>
</div>
<body>
<html>
EOD;

echo "$theResults";
?>

Expert:  abhi_iitian replied 5 years ago.

Php needs to know a SMTP address from which it can send emails.

You should have a php.ini file somewhere in your php installation.

At wamp5 (down left) – Config files – php.ini

If you cannot locate that, it will be Most likely at :

C:\wamp\bin\php\php5.2.5\php.ini
C:\wamp\bin\apache\apache2.2.6\bin\php.ini


Look for the following in your PHP.ini file

 

Locate these lines

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25


and paste in your isp SMTP address (this is the one you were given by your ISP for entering into Outlook or Thunderbird):

change "localhost" to your own isp's SMTP address ( the same one you enter in your email program like if you use gmail its smtp.gmail.com and port 587 ) so that it besomes :

[mail function]
; For Win32 only.
SMTP = mail.myisp.net; for Win32 only
smtp_port = 25
sendmail_from=XXX@XXXXXX.XXX ; for Win32 only

say for gmail it will become :

SMTP = smtp.gmail.com
smtp_port = 587

Abhi
Customer: replied 5 years ago.

My configuration Php.ini

 

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 587

; For Win32 only.
;sendmail_from = XXXXX@XXXXXX.XXX.

 

Thank you for Reply ...but I had the same error..the point is I would like to send the message to my email gmail or hotmail I dont like use outlook . so let me know please is the correct configuration.

 

Thank you so much, ask for aditional info

 

Eduardo

Expert:  abhi_iitian replied 5 years ago.

You will need sendmail for this, follow the instructions at :

http://digiex.net/guides-tutorials/544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl.html


You can also refer this link(with gmail instead of godaddy.. that is settings required for gmail you can see from above link) :

http://www.joshstauffer.com/tech/send-test-emails-with-wampserver/

If you want to use phpmailer, follow the steps given below(there is no choce to fill the form in that case) :

http://deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php-with.html



Abhi
Customer: replied 5 years ago.

Hi Abhi:

 

I tried the second option,now is better, no error, but I didn't recieved any email in my account Gmail.

 

Thank you

 

Eduardo

Expert:  abhi_iitian replied 5 years ago.

You mean you used phpmailer ?
Customer: replied 5 years ago.
Expert:  abhi_iitian replied 5 years ago.

Okay so used that method.. fine.. so you must have these now in sendmail file

  • line 14 | smtp_server=smtp.gmail.com
  • line 18 | smtp_port=587
  • line 38 | auth_username=youremail@gmail.com
  • line 39 | auth_password=yourgmailpassword
Also, in php.ini you should have :

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from =XXX@XXXXXX.XXX

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t"


The mail would be send from your gmail account to te
Expert:  abhi_iitian replied 5 years ago.

Okay so used that method.. fine.. so you must have these now in sendmail file

  • line 14 | smtp_server=smtp.gmail.com
  • line 18 | smtp_port=587
  • line 38 | auth_username=youremail@gmail.com
  • line 39 | auth_password=yourgmailpassword
Also, in php.ini you should have :

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from =XXX@XXXXXX.XXX

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\inetpub\sendmail\sendmail.exe -t"


The mail would be send from your gmail account to the webmaster address , I mean it will be sent to the address you specify in your form by the field $webmaster

Abhi
Customer: replied 5 years ago.

I did:

; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail

[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=smtpout.secureserver.net

; smtp port (normally 25)

smtp_port=80

; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL

;smtp_ssl=auto

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

;default_domain=mydomain.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=XXXXX@XXXXXX.XXX
auth_password=2301060

; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.

;pop3_server=
;pop3_username=
;pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content

;force_sender=

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content

;force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required

hostname=

 

Php.ini:

 

[mail function]
; For Win32 only.
SMTP =
;smtp_port = 587

; For Win32 only.
;sendmail_from =

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path =c:\wampsendmail\sendmail.exe -t

 

Expert:  abhi_iitian replied 5 years ago.
Sorry for the delay.

In the sendmail you do not seem to have entered gmail smtp settings :

smtp_server=smtpout.secureserver.net

; smtp port (normally 25)

smtp_port=80

 

should be

 

  • line 14 | smtp_server=smtp.gmail.com
  • line 18 | smtp_port=587
Customer: replied 5 years ago.

I'm sorry it doesn't work yet....... have this error log:

 

09/07/01 22:26:48 : Connect timed out.
09/07/01 22:30:19 : Authentication failed.<EOL>
09/07/01 22:44:10 : Message is missing sender's address
09/07/01 22:45:36 : Authentication failed.<EOL>
09/07/05 11:47:30 : Must issue a STARTTLS command first. k37sm25031552rvb.58<EOL>

Customer: replied 5 years ago.

Bebug error in Sendmail:

 

09/07/05 11:47:29 ** --- MESSAGE BEGIN ---
09/07/05 11:47:29 ** To:XXX@XXXXXX.XXX
09/07/05 11:47:29 ** Subject:
09/07/05 11:47:29 ** From:XXX@XXXXXX.XXX
09/07/05 11:47:29 ** Content-type: text/html
09/07/05 11:47:29 **
09/07/05 11:47:29 **
09/07/05 11:47:29 ** <br><hr><br>
09/07/05 11:47:29 ** Name: Edgardo Domingo <br>
09/07/05 11:47:29 ** Email:XXX@XXXXXX.XXX <br>
09/07/05 11:47:29 ** Phone Number: XXXXXXXXX <br>
09/07/05 11:47:29 ** //Spending Plans: <br>
09/07/05 11:47:29 ** //Number of Items: <br>
09/07/05 11:47:29 ** Comments: fdgdfdfghdf <br>
09/07/05 11:47:29 ** //Newsletter: <br>
09/07/05 11:47:29 ** --- MESSAGE END ---
09/07/05 11:47:29 ** Connecting to smtp.gmail.com:587
09/07/05 11:47:30 ** Connected.
09/07/05 11:47:30 << 220 mx.google.com ESMTP k37sm25031552rvb.58<EOL>
09/07/05 11:47:30 >> EHLO Eduardo-PC<EOL>
09/07/05 11:47:30 << 250-mx.google.com at your service, [98.232.101.150]<EOL>250-SIZE 35651584<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250 PIPELINING<EOL>
09/07/05 11:47:30 ** Authenticating asXXX@XXXXXX.XXX
09/07/05 11:47:30 >> MAIL FROM: <XXXXX@XXXXXX.XXX><EOL>
09/07/05 11:47:30 << 530 5.7.0 Must issue a STARTTLS command first. k37sm25031552rvb.58<EOL>
09/07/05 11:47:30 ** Disconnecting from smtp.gmail.com:587
09/07/05 11:47:30 ** Disconnected.
09/07/05 11:47:30 ** Disconnected.
09/07/05 11:47:30 ** Must issue a STARTTLS command first. k37sm25031552rvb.58<EOL>

Expert:  abhi_iitian replied 5 years ago.

The reason for this is that gmail uses secure (TLS) servers to prevent spam.

MAke sure, you have :

smtp_ssl=auto


in sendmail file

If it us there, To solve this problem you need to download the following zip file:
http://glob.com.au/sendmail/sendmail-SSL.zip
and install its contents in the sendmail directory. That will make sendmail.exe TLS compatible.
abhi_iitian, Computer Software Engineer
Category: Programming
Satisfied Customers: 1757
Experience: B-Tech Topper in CSE from IIT Roorkee, Experience as S/W design Engineer at Microsoft India
abhi_iitian and other Programming Specialists are ready to help you
Customer: replied 5 years ago.

Okey I tried with the first and didn't work.....so I have to erase sendmail.exe? and install yours?

Expert:  abhi_iitian replied 5 years ago.

don't erase the earlier one... just unzip the new file and copy the files inside it into existing sendmail directory
Customer: replied 5 years ago.

Sure!!! Worked.....thank you so much

 

Eduardo

Expert:  abhi_iitian replied 5 years ago.

okay great. Thanks

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5603
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/unvadim/2010-11-15_210218_avatar.jpg unvadim's Avatar

    unvadim

    Computer Software Engineer

    Satisfied Customers:

    1158
    Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    950
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    864
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/RA/rajivsharma086/2012-6-6_17128_displaypic.64x64.jpg Raj's Avatar

    Raj

    Computer Engg.

    Satisfied Customers:

    860
    BE CS, 4+ Experience in Programming and Database (ERP)
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    590
    11 yrs of programming (PHP, WordPress, XSL, SQL, JavaScript)