0

I want to send an email confirmation with PHP when a user subscribes in my HTML page. I have a redirect page but I need to sent an email and let him know that he did subscribe. Here is my php. Can I do it fro the same php?

<?php
/* Set e-mail recipient */
$myemail  = "example@domain";
$subject  = "You have a new subscriber!";

/* Check all form inputs using check_input function */
$email    = check_input($_POST['email']);

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}

/* Let's prepare the message for the e-mail */
$message = "Hello!

An email has been submitted by:

E-mail: $email

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the success page */
header('Location: success.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

This the php I'm using! Can anyone help!!!! Thanks in advanced

1 Answers1

1

code snippet for sending mail

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

$message can be a html markup

If you are looking for some thirdparty way

https://github.com/Synchro/PHPMailer

Manju
  • 668
  • 7
  • 22