Jump to content
Larry Ullman's Book Forums

Sending Email - Script 8.10

Recommended Posts

Hi, I am using Xampp 3.2.2 and have written script 8.10 below (Page 228) but I just can´t get an e-mail. Everything looks fine but I get no e-mail at all. PIease help!






<?php // Script 8.10 - 19_register.php

/*This page lets people register for the site in theory*/


//Set the page title and include the header file:

define ('TITLE', 'Register');

include ('templates/19_header_v6.html');


//print some introductory text:

print '<div id = "leftcontent">

<h2>Registration Form</h2>

<p>Register so that you can take advantages of certain features like this, that and the other thing.</p>';


//Check whether the form has been submitted (handle form if):



$problem = false;


//Check for each value:


if (empty ($_POST['first_name'])){

$problem = TRUE;

print '<p class="text--error">Please enter your first name!</p>';


if (empty ($_POST['last_name'])){

$problem = TRUE;

print '<p class="text--error">Please enter your last name!</p>';


// Change the email validation(from 19_rigister_v11.php file) so that it also checks for a single "at" symbol:


if (empty ($_POST['email']) || (substr_count ($_POST['email'], '@')!=1)){

$problem = TRUE;

print '<p class="text--error">Please enter your email!</p>';


//Validate the password:

if (empty ($_POST['password1'])){

$problem = TRUE;

print '<p class="text--error">Please enter your password!</p>';


if ($_POST['password1'] != $_POST['password2']){

$problem = TRUE;

print '<p class="text--error">Your password did not match your confirmed password!</p>';


// Check whether a problem occured:


if (!$problem){

print '<p>You are now registered!<br />Okay, you are not really registered but ...</p>';


//Send the email:


$body = "Thank you, {$_POST['first_name']}, for registering with the J.D. Salinger fan club!";

mail($_POST['email'], 'Registration Confirmation', $body, 'From:me@example.com');


}else{ //Forgot a field

print '<p>Please try again!</>';



/*if (!problem){ // if there weren´t any problems ...

print '<p class ="text--success">You are now registered!<br />Okay, you are not really registerd but ...</p>';

//$_POST = [];

}else{//Forgot a field:

print '<p class = "text--error">Please try again!</p>';



} // End of handle form if: if ($_SERVER['REQUEST_METHOD'] =='POST'){



<!--Display the form-->


<form action="19_register_v12.php" method="post" class="form--inline">


<!-- Create the sticky first name, last name and email inputs-->


<p><label for="first_name">First Name: </label><input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])){

print htmlspecialchars($_POST['first_name']);



<p><label for="last_name">Last Name: </label><input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])){

print htmlspecialchars($_POST['last_name']);



<p><label for="email">Email Address: </label><input type="email" name="email" size="20" value="<?php if (isset($_POST['email'])){

print htmlspecialchars($_POST['email']);



Password: <input type = "password" name = "password1" size = "20"/><br /><br />

Confirm Password: <input type = "password" name = "password2" size = "20" /><br /><br />


<p><input type="submit" name="submit" value="Register!" class="button--pill"></p>





print '</div>';

require ('templates/19_footer_v6.html');


Link to comment
Share on other sites

Hi, Larry.


Sorry for my late feedback.


I am using Windows 7 and my e-mail from gmail  but I cann´t just the email. Please see below the last message I got:


Warning: mail(): SMTP server response: 553 We do not relay non-local mail, sorry. in C:\XAMPP\htdocs\19_register_v12.php on line 51


Thanks a lot,



Link to comment
Share on other sites

  • 2 weeks later...

Ah, so this is relatively common on Windows. How critical is it for you to get this working? I don't normally bother when developing locally (because it is a big pain). If it's a must, I'd look at some of the solutions you'll find online:



Link to comment
Share on other sites

  • 7 months later...


I am also working on script 8.10 and received the following error when I tried to send the email: 

Warning: 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 C:\xampp\htdocs\CreatingWebAppsCh8\register.phpon line 44.

this is my line 44: mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com');

I am running win10 on a 64bit system, xampp v3.2.2 and when I looked at the phpinfo.php file it was set for 


but this is what the php.ini file has:

[mail function]
; For Win32 only.
; http://php.net/smtp
; http://php.net/smtp-port

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

I added the ini_set

 ini_set("smtp_port", 25);
mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com');

and received the same error message.

I have looked at several different sources, including the php site and am still at a loss.

Link to comment
Share on other sites


  • Create New...