Skip navigation
Currently Being Moderated

Email not sending

Aug 22, 2012 3:53 AM

Could anyone help please. I am having a problem receiving emails through xampp/localhost. I have built the form and when I fill it in the message tells me that the mail has been sent. I do not get any error messesages.

 

I have attached the php page code and also the php.ini fail function from xampp

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Me</title>
</head>
<body>
<h1>Contact Me</h1>
<?php # Script 10.1 - email.php
// Check the form submission:
if (isset($_POST['submitted'])) {

// Minimal form validation
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) {
  
   // Create the body:
   $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}";
  
   // Make it no longer than 70 caracters long:
   $body = wordwrap($body, 70);
  
   // Send the mail:
   mail('paul@wcrltd.co.uk', 'Contact form submission', $body, "From {$_POST['email']}");
  
   // Print a message:
   echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>';
  
   // Clear $_POST (So that the forms not sticky):
   $_POST = array();
  
} else {
   echo '<p style="font-weight: bold; Color: #c00">Please fill out the form completley.</p>';
}

} // End of main isset() IF.
// Create the HTML form
?>
<p>Please fill out this form to contact me.</p>
<form action="email.php" method="post">
<p>Name: <input type="text" name="name" size="30" maxlengh="60" value="<?php if (isset($_POST['name'])) echo $_post['email']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="30" maxlengh="80" value="<?php if (isset($_POST['email'])) echo $_post['email']; ?>" /></p>
<p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_post['comments']; ?> </textarea></p> 
<p><input type="submit" name="submit" value="Send!" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>

 

 

 

[mail function]
XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = mail.wcrltd.co.uk
smtp_port = 25

For Win32 only.
http://php.net/sendmail-from
sendmail_from = paul@wcrltd.co.uk

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path. 

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"

[SQL]
; http://php.net/sql.safe-mode
sql.safe_mode = Off

 
Replies
  • Currently Being Moderated
    Aug 22, 2012 4:20 AM   in reply to peterattrsb

    peterattrsb wrote:

     

    Could anyone help please. I am having a problem receiving emails through xampp/localhost. I have built the form and when I fill it in the message tells me that the mail has been sent. I do not get any error messesages.

     

     

    Why do you need it to work through xampp/localhost?

     

    It works on a remote, right?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2012 5:26 AM   in reply to peterattrsb

    peterattrsb wrote:

     

    Because I'm new to Dreamweaver so I am building a test site on my hard drive, following the book. According to the book you can do this email test using the local server. I'm not sure if it works on a remote server not sure how to do that yet.

     

    I would'nt worry too much if it doesn't work on your local set-up......I can tell you your form will work once you upload it to a remote server assuming it has php running, I've tested it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 22, 2012 5:59 AM   in reply to peterattrsb

    peterattrsb wrote:

     

    Thanks osgood I have just tested it on the remote server and the form works fine. It would just be nice to get it working on localhost so I am not having to upload odd files to the server all the time.

     

    Simple, my guess is you are using Windows and Windows does not have a Mail server installed in it by default.  This is one of the differences you will find of developing for Apache/PHP/mySQL in a Windows environment.  Nothing to be alarmed about.  If you want to send mail you will have to send it through your ISP.  So to do this, open up php.ini (or this may be in a different location with XAMPP, I personally don't like their package so I only know the "real" location).  Look for the following:

     

    smtp_server=[value]

    smtp_port=[value]

    auth_username=[value]

    auth_password=[value]

     

    Now this can be your ISP, or I believe you may be able to make it work.  Checked online and if you use smtp.gmail.com with the port 465 and username "youremail@gmail.com" it should work  If you use your ISP, they should be able to provide you with the settings to set this up.  This will make all emails you send from the script, from your own email address.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points