Page 1 of 2
Problem in sending email from localhost
Posted: Thu Jan 20, 2011 11:53 pm
by shariefbe
Hi friends,
I have designed and one form and php code to send mail. I am developing this in my localhost,
So now i want to send email from my localhost to test my programming.
I googled and i find something like editing "php.ini" file. But it didnt work for me.
So can anyone help me and i am using wamp server.
Thank you.
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 1:42 am
by social_experiment
Do you receive any error messages when attempting to send an email? Take a look at this url
http://www.wampserver.com/phorum/read.p ... #msg-70522
Hth
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 4:02 am
by shariefbe
I already downloaded phpmailer. But i dont know how to use that php mailer.
I am not getting any wrror message.
for you referencec i will post my code with this post
Code: Select all
<form name="contactform" method="post" action="sendmail.php">
<tbody><tr>
<td colspan="2" class="text" valign="top"><strong>Please fill the following mandatory fields to get quick response from our edtech team.</strong></td>
</tr>
<tr>
<td valign="top" width="36%"> </td>
<td class="h2" align="right" valign="top" width="64%"> <span class="red-text">required field *</span></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> Name : </td>
<td valign="top"><input name="name" class="input" size="35" type="text"></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> Company :</td>
<td valign="top"><input name="company" class="input" id="Company" size="35" type="text"></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> E-mail : </td>
<td valign="top"><input name="email" class="input" size="35" type="text"></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> Contact No: </td>
<td valign="top"><input name="contact" class="input" size="35" type="text"></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> Address :</td>
<td valign="top"><input name="address" class="input" id="Address" size="35" type="text"></td>
</tr>
<tr>
<td class="text" valign="top"><span class="red-text">*</span> Requirment </td>
<td valign="top"><textarea name="description" cols="38" rows="4" class="input" id="Description"></textarea></td>
</tr>
<tr>
<td class="heading3" valign="top"> </td>
<td valign="top"><input name="submit" value="Submit Now" class="more-button2" type="submit">
<input name="Reset" value="Reset" class="more-button2" type="reset"></td>
</tr>
</tbody>
</form>
Now sendmail.php code
Code: Select all
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "shariefbe@gmail.com";
$email_subject = "Inquiry from you']";
/* function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['company']) ||
!isset($_POST['email']) ||
!isset($_POST['contact']) ||
!isset($_POST['address']) ||
!isset($_POST['description'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/
$name = $_POST['name']; // required
$company = $_POST['company']; // required
$email_from = $_POST['email']; // required
$contact = $_POST['contact']; // not required
$comments = $_POST['description']; // required
/* $error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";*/
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $comments, $headers); }
?>
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 4:41 am
by social_experiment
Code: Select all
@mail($email_to, $email_subject, $comments, $headers);
Remove the '@' in front of the mail() function. Then you should receive an error message. Once it's fixed you can replace the '@'
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 4:58 am
by shariefbe
yes, when i remove this '@" symbol. I am getting the below warning as
"Warning: mail() [function.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 F:\test\xampp\htdocs\sendmail.php on line 42'
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 5:14 am
by josh
PHP mailer is not an SMTP server, its just a wrapper for the regular mail() function for the most part.
Re: Problem in sending email from localhost
Posted: Fri Jan 21, 2011 6:29 am
by shariefbe
Now i am not using php mailer. Now i a using mercury smtp server which come from "xampp".
Re: Problem in sending email from localhost
Posted: Sat Jan 22, 2011 7:36 am
by josh
First enable telnet, then open a command line and try "telnet localhost 25". Try to manually send an email over the command line
http://www.wikihow.com/Send-Email-Using-Telnet
Re: Problem in sending email from localhost
Posted: Fri Jan 28, 2011 6:32 am
by shariefbe
Thanks for your reply
If i follow the steps in that link i am getting one error when i use
'MAIL FROM:you@server.com."
"Must issue a STARTTLS command first"
So i used that command first and then used the "MAIL FROM" command. But the connection is getting lost when i use this STARTTLS command.
So please help me
Re: Problem in sending email from localhost
Posted: Fri Jan 28, 2011 9:04 pm
by shariefbe
Now i am getting this following error
Code: Select all
Warning: mail() [function.mail]: SMTP server response: 550-5.7.1 [122.162.237.107] The IP you're using to send mail is not authorized 550-5.7.1 to send email directly to our servers. Please use the SMTP relay at 550-5.7.1 your service provider instead. Learn more at 550 5.7.1 http://mail.google.com/support/bin/answer.py?answer=10336 f1si42544973wfp.91 in F:\test\xampp\htdocs\sendmail.php on line 43
Can any one help me plz. I am struck with this from long time...
Re: Problem in sending email from localhost
Posted: Sat Jan 29, 2011 3:19 am
by Zyxist
In order to send e-mails from localhost, you must install a mail server on your computer and configure it to send mails. All PHP does is passing the message to the mail server and nothing more. It does not send it anywhere else. There is however an alternative. You can register some mailbox at some external server (i.e. at GMail), and connect to it directly via SMTP. It requires from you to handle the entire protocol manually, and in case of GMail, you must also encrypt the transmission with SSL (OpenSSL extension should be installed), but it works and does not require chaning php.ini. There are some mailing libraries that can handle it for you, i.e. SwiftMailer. PHP mail() function won't work here, because the configuration for it supports neither authentication nor encryption.
Personally, I use a very simple solution for handling mails at localhost. I wrote a simple program in C with less than 1KB of code that reads the mails from the standard input and simply saves them as files on the hard disk. PHP thinks the mail has been sent, I have the message content, and everyone is happy

.
Re: Problem in sending email from localhost
Posted: Tue Feb 01, 2011 4:26 am
by josh
shariefbe wrote:Thanks for your reply
If i follow the steps in that link i am getting one error when i use
'MAIL FROM:you@server.com."
"Must issue a STARTTLS command first"
So i used that command first and then used the "MAIL FROM" command. But the connection is getting lost when i use this STARTTLS command.
So please help me
Turn off the TLS on the localhost's MTA (mail server), also lock it down to sending emails originating from localhost only. Then, try again and post back, thanks! Alternatively switch to a client with TLS support (3rd party mail library for PHP, or outlook express for testing the mail server outside of PHP). I'd recommend turning off TLS because that's 100x harder to configure than the basic mail server, get the basics working first.
Re: Problem in sending email from localhost
Posted: Tue Feb 01, 2011 9:42 am
by shariefbe
Zyxist wrote:In order to send e-mails from localhost, you must install a mail server on your computer and configure it to send mails. All PHP does is passing the message to the mail server and nothing more. It does not send it anywhere else. There is however an alternative. You can register some mailbox at some external server (i.e. at GMail), and connect to it directly via SMTP. It requires from you to handle the entire protocol manually, and in case of GMail, you must also encrypt the transmission with SSL (OpenSSL extension should be installed), but it works and does not require chaning php.ini. There are some mailing libraries that can handle it for you, i.e. SwiftMailer. PHP mail() function won't work here, because the configuration for it supports neither authentication nor encryption.
Personally, I use a very simple solution for handling mails at localhost. I wrote a simple program in C with less than 1KB of code that reads the mails from the standard input and simply saves them as files on the hard disk. PHP thinks the mail has been sent, I have the message content, and everyone is happy

.
i dont want to encrypt anything. Just i want to check whether my code is right. for that i am using "xampp". it contains mercury mail server inbuilt. i started that service before sending the mail. even though its not working....
Re: Problem in sending email from localhost
Posted: Tue Feb 01, 2011 12:58 pm
by josh
The most recent error you post is because you're trying to use Google's SMTP servers without a non Google account. Use localhost, not mail.google.com Disable TLS, you want no encryption.
Re: Problem in sending email from localhost
Posted: Wed Feb 02, 2011 12:35 am
by shariefbe
josh wrote:The most recent error you post is because you're trying to use Google's SMTP servers without a non Google account. Use localhost, not mail.google.com Disable TLS, you want no encryption.
I have mail accounts in gmail and yahoo...I am trying this from my home. Now what to use as smtp?