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: 7 years ago.
Category: Programming
Expert:  abhi_iitian replied 7 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 7 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 = '[email protected]';

/* 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 7 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
[email protected] ; for Win32 only

say for gmail it will become :

SMTP = smtp.gmail.com
smtp_port = 587

Abhi
Customer: replied 7 years ago.

My configuration Php.ini

 

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

; For Win32 only.
;sendmail_from = [email protected].

 

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 7 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 7 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 7 years ago.

You mean you used phpmailer ?
Customer: replied 7 years ago.
Expert:  abhi_iitian replied 7 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 | [email protected]
  • 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 [email protected]

; 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 7 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 | [email protected]
  • 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 [email protected]

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

[email protected]
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 7 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 7 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 7 years ago.

Bebug error in Sendmail:

 

09/07/05 11:47:29 ** --- MESSAGE BEGIN ---
09/07/05 11:47:29 ** To:[email protected]
09/07/05 11:47:29 ** Subject:
09/07/05 11:47:29 ** From:[email protected]
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:[email protected] <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 [email protected]
09/07/05 11:47:30 >> MAIL FROM: <[email protected]><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 7 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 and 2 other Programming Specialists are ready to help you
Customer: replied 7 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 7 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 7 years ago.

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

 

Eduardo

Expert:  abhi_iitian replied 7 years ago.

okay great. Thanks

Related Programming Questions