Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6972759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:00:44+00:00 2026-05-27T17:00:44+00:00

I’ve had something strange happen lately with php script I use to send emails

  • 0

I’ve had something strange happen lately with php script I use to send emails from an online contact form and just wondered if any one could shed a little light on the issue.

I’ve had a php script which I use on multiple websites and it has always worked fine, but for some strange reason, I tried using in on one site and it just wasn’t working.

I tried fiddleing with it and eventually realised that it was something to do with the following section of code:

this is the original section of code that usually works fine, but wasn’t working for some reason:

$to = 'My Name <info@mydomain.com>';

I then removed the name bit, so that the code looked like this:

$to = 'info@mydomain.com';

and now it sends the email through ok.

As I say, the top code usually works fine, so any ideas why this time I had to alter the code to get it to work?

Any possible explanations would be great :o)

Here’s the full code:

<?php

require("is_email.php"); // email validation function

//Retrieve form data.   
//GET - user submitted data using AJAX  
//POST - in case user does not support javascript, we'll use POST instead  
$name = ($_GET['name']) ?$_GET['name'] : $_POST['name'];  
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];  
$telephone = ($_GET['telephone']) ?$_GET['telephone'] : $_POST['telephone'];
$address = ($_GET['address']) ?$_GET['address'] : $_POST['address'];
$enquiry = ($_GET['enquiry']) ?$_GET['enquiry'] : $_POST['enquiry'];
$calculation = ($_GET['calculation']) ?$_GET['calculation'] : $_POST['calculation']; 

//flag to indicate which method it uses. If POST set it to 1  
if ($_POST) $post=1;

//Server side validation for POST data
if (!$name) $errors[count($errors)] = 'Please click back and enter your name.';  
if (!$email) $errors[count($errors)] = 'Please click back and enter your email.'; 
else if (!is_email($email)) $errors[count($errors)] = 'Please click back as you may have entered an invalid email address.';
if (!$telephone) $errors[count($errors)] = 'Please click back and enter your telephone number.';
if (!$address) $errors[count($errors)] = 'Please click back and enter your address.';
if (!$enquiry) $errors[count($errors)] = 'Please click back and enter your enquiry.';
if ($calculation != '14') $errors[count($errors)] = 'Please click back and check you have correctly answered the simple calculation (in number format).';

//if the errors array is empty, send the mail  
if (!$errors) {

    //recipient - change this to your name and email  
    $to = 'info@mydomain.com';     
    //sender  
    $from = $name . ' <' . $email . '>';

    //subject and the html message  
    $subject = 'Website Enquiry: ' . $name;   
    $email_body = '  
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head></head>  
    <body>  
    <table cellpadding="5" style="color:#757575;">  
        <tr><td style="color:#3b5998;">Name: </td><td>' . $name . '</td></tr>  
        <tr><td style="color:#3b5998;">Email: </td><td>' . $email . '</td></tr>  
        <tr><td style="color:#3b5998;">Telephone: </td><td>' . $telephone . '</td></tr>
        <tr valign="top"><td style="color:#3b5998;">Address: </td><td>' . nl2br($address) . '</td></tr>
        <tr valign="top"><td style="color:#3b5998;">Enquiry: </td><td>' . nl2br($enquiry) . '</td></tr>  
    </table>  
    </body>  
    </html>';

    //send the mail  
    $result = sendmail($to, $subject, $email_body, $from);

    //if POST was used, display the message straight away  
    if ($_POST) {  
        if ($result) echo 'Thank you! We have received your message.<br /><br /><a href="../enquiry_form.html">OK</a>';  
        else echo 'Sorry, unexpected error. Please try again later';

        //else if GET was used, return the boolean value so that   
        //ajax script can react accordingly  
        //1 means success, 0 means failed  
        } else {  
            echo $result;     
        }

//if the errors array has values  
} else {

    //display the errors message  
    for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br />';    
    exit;  
}

//Simple mail function with HTML header  
function sendmail($to, $subject, $email_body, $from) {  
    $headers = "MIME-Version: 1.0" . "\r\n";  
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";  
    $headers .= 'From: ' . $from . "\r\n";  

    $result = mail($to,$subject,$email_body,$headers);  

    if ($result) return 1;  
    else return 0;  
}  
?>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:00:45+00:00Added an answer on May 27, 2026 at 5:00 pm

    I edited my initial question to explain how I overcame the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.