Jump to content

Mail() function always returns false


ggkolfin
 Share

Recommended Posts

Hello! I am trying to make a contact form and hoping for some help because I cannot make the thing work! The data entered by the user should be sent to my hotmail account eg me@hotmail.com. I have created this html form:

<form method="post" name="contact_form" action="doContact.php"><input type="text" name="name" placeholder="Name" size="50"  autocomplete="off" autofocus><br /><input type="text" name="mail" placeholder="e-mail" size="50" autocomplete="off" required><br /><input type="text" name="subject" placeholder="Subject" size="50" autocomplete="off"><br /><textarea  name="message" placeholder="Message" maxlength="1000" cols="43" rows="6" autocomplete="off" required></textarea><br /><input type="submit" value="SEND"></form>

The doContact.php file contains the following code:

<?php ini_set('display_errors', 1); error_reporting(E_ALL);$name=$_POST['name'];$mail=$_POST['mail'];$subject=$_POST['subject'];$message=$_POST['message'];$message = str_replace("n.", "n..", $message);$message = wordwrap($message, 70, "rn");$to="me@hotmail.com";$body="From ".$name." with e-mail: ".$mail." message: ".$message;if (mail ($to, $subject, $body)==TRUE) {         echo "<p>Your message has been sent!</p>";    }else{         echo "<p>Something went wrong, please try again!</p>";     }?>

I am working in Windows8 x64 with WampServer v2.5, so at the beginning I was getting a:

mail():Failed to connect to mailserver at "localhost" port 25

error and my <p>Something went wrong, please try again!</p> was "echoing".

I did a lot of search and I discovered that this was because I didn't have any mail server installed. Instead of installing a mail server, and after I unsuccessfully tried to edit the php.ini with hotmail's smtp, port and my account credential (it didn't make any difference, I was still getting the mail():Failed to connect to mailserver at "smtp.live.com" port 465) I chose to first try the solution pointed here.

So I downloaded the sendmail app and changed my php.ini and sendmail.ini accordingly (meaning with the smtp and pop3 data of hotmail and my account credentials, as instructed).

I restarted wamp and tested again: now it does not return any error but the mail returns false, so I get the "<p>Something went wrong, please try again!</p>" message and the mail is not sent.

Do you know how to fix this?

Also, if I cannot make this work and I try to install a mail server locally to test my code, does that mean that after uploading my site in an actual hosting server online (not localhost) the local mail server will NOT be required anymore?

I know this is a noob question but I am very new to this...

Any help will be very much appreciated!

Thank you all!

 

Edited by ggkolfin
Link to comment
Share on other sites

Thank you for your reply. I deleted my original sendmail directory from wamp/ and started from the beginning following the instructions of the article. I also changed my php $to variable to my gmail account eg me@gmail.com in order to do the same changes as the author. I installed stunnel and changed the conf file and the sendmail.ini and php.ini as instructed. Double checked the author's file references to be sure... Unfortunately the mail() still returns false and of course the mail is not sent. :-( Any other suggestions?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...