Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem with simple mail form

Featured Replies

Hi all,

 

It has been a while since iv done any php and im trying to make a simple textboook mail form but cant see what im doing wrong.

 

 

                <form action="" method="post">
                    Want us to call you? <input type="text" placeholder = "Please enter a contact number" class="callBackField" name="callBackField">
                    <input type="submit" value="Call me back" class="callBackSubmit">    
                </form>    
 

 

<?php


if (isset($_POST['callBackSubmit']))


{
$to = "dgeorge@live.co.uk";
$subject = "Call me back, Guild Bathrooms";
$message = $_POST['callBackField'];
$from = "mail.guildbathrooms.com";
mail($to,$subject,$message);
echo "Mail Sent.";
}


?>
 

the action field is left blank because the php is on the same page as the html, im pretty sure i have done something wrong in the php, any help would ne greatly appreciated.

 

Thanks for looking

 

Best regards

 

David

 

1. Although setting the form action to nothing will theoretically work I have found that not all servers will accept this. Setting the action to:

 

 

<?php echo htmlentities($_SERVER['PHP_SELF']); ?>
 

or

 

 

<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>
 

Will solve the issue.

 

Note: Most modern servers will default to one of these methods automatically if the action is set to

 

<?php echo $_SERVER['PHP_SELF']; ?>

 

2. You are not setting any headers to the mail function.

 

Many servers will not allow a mail to send if it is not from an email on that domain:

 

You have a $from variable:

$from = "mail.guildbathrooms.com";
$headers = "From: $from";

Try

 

 

<?php


if (isset($_POST['callBackSubmit']))


{
$to = "xxxxxxx@livexxxx.co.uk";
$subject = "Call me back, Guild Bathrooms";
$message = $_POST['callBackField'];
$from = "mail.guildbathrooms.com";
$headers = "From: $from";
mail($to,$subject,$message;$headers);
echo "Mail Sent.";
}


?>
 

Edited by nfc212

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.