Easy PHP Email Script Question

Posted on 2007-10-07
Last Modified: 2013-12-13
I need to make a sender and a subject show up when the email is sent. Where would I put  it?


$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
$childsname = $_POST['childsname'];
$childsage = $_POST['childsage'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$dayphone = $_POST['dayphone'];
$evephone = $_POST['evephone'];
$class1 = $_POST['class1'];
$class2 = $_POST['class2'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;

if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back Button To Make Changes</h2>\n";

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = "$todayis [EST] \n
Attention: $attn \n
From: $visitor ($visitormail)\n
Childs Name: $childsname \n
Childs Age: $childsage \n
Address: $address \n
Address2: $address2 \n
City: $city \n
State: $state \n
Zip: $zip \n
Class1: $class1 \n
Class2: $class2 \n
Daytime Phone: $dayphone \n
Evening Phone: $evephone \n
Message: $notes \n

$from = "From: $visitormail\r\n";

mail("", $subject, $message, $from);


    LVL 21

    Accepted Solution

    A simple example which shows where to put subject and sender email address:

    $email = $_GET['email'] ;
    $message = $_GET['message'] ;

    // This is the important line below
    mail( "", "Email Subject", $message, "From: $email" );
    print "Congratulations your email has been sent";

    For a simple tutorial and more examples and explanation, go here:

    Let me know how you get on.
    LVL 4

    Assisted Solution

    You can check if the mail has been sent correctly and then show the info you require by replacing the line

    mail("", $subject, $message, $from);


    if (@mail("", $subject, $message, $from);) {
           echo "<h2>Your message has been sent</h2><br>\n";
           echo "<h2>Message sent by - " . $from . "</h2><br>\n";
           echo "<h2>Message subject - " . $subject . "</h2><br>\n";
    } else {
           echo "<h2>Sorry, there has been a problem, your message has not been sent</h2><br>\n";

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now