CAn't get this really simple script to work

Posted on 2008-06-17
Last Modified: 2013-12-12
I have this php code that im using.  The goal is to create an input box where people can send their email address.  

once the user clicks on the submit button, the email that was put into the input box would be sent to an email address of my choosing



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



        $user_email = $_POST['email'];


        $to = ''; // your email address here

        $subject = 'New sign up'; // change this as desired

        $message = 'A New user has signed up, email address: ' . $user_email; // change this as desired


        $headers  = 'MIME-Version: 1.0' . "\r\n";

        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

        $headers .= 'From:' . "\r\n" . 'X-Mailer: PHP/' . phpversion();


        mail ( $to, $subject, $message, $headers );


        $to = $user_email;

        $subject = ''; // yourdomain here

        $message = 'Thank you for signing up to'; // change this as desired


        mail ( $to, $subject, $message, $headers );






<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">

        <input type="text" name="email" /><input type="submit" value="sign up" />


Open in new window

Question by:djmichaelray
LVL 18

Accepted Solution

Matthew Kelly earned 500 total points
ID: 21809245
If you do not have a email server running on the machine running PHP, mail will not work.

Is the problem with the email being sent?

If so, the best approach is to use a 3rd party mail program. In the past I have used PHPMailer

Below is the PHP code to use it. Place class.phpmailer.php into your php includes directory.

Replace text in << >> with your server information:




$mail = new PHPMailer();


$mail->IsSMTP(); // send via SMTP

$mail->Host     = "<<smtpserver>>:<<stmpport>>"; // SMTP servers

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "<<uname>>"; // SMTP username

$mail->Password = "<<pword>>"; // SMTP password

$mail->From = "<<email address from>>";

$mail->FromName = "<<email name from>>";

$mail->AddAddress("<<email address to>>"); 

$mail->AddReplyTo("<<email address from>>","<<email name from>>");

$mail->WordWrap = 50; // set word wrap

$mail->IsHTML(true); // send as HTML

$mail->Subject  =  "Subject";

$mail->Body     =  "Body text";

$mail->AltBody  =  $mail->Body;





Open in new window

LVL 14

Expert Comment

ID: 21809273
My thought is it's either a server setup issue or being caught by a spam filter:

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

747 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

13 Experts available now in Live!

Get 1:1 Help Now