Domanda

I tried asking this before but I think I made things too complicated and nobody answered. This is take two. I need to add a phone number field to this line of PHP. I have NO IDEA how to add it.

mail( "contact@jeremyblaze.com", "Contact Form: ".$_POST['name'], $_POST['text'], "From:" . $_POST['email'] );

I've tried this, but the email never goes through.

mail( "contact@jeremyblaze.com", "Contact Form: ".$_POST['name'], $_POST['phone'], $_POST['text'], "From:" . $_POST['email'] );

Here's the full PHP if you need it.

<?php
if ( isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['name']) && isset($_POST['text']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

    $test = "/(content-type|bcc:|cc:|to:)/i";
    foreach ( $_POST as $key => $val ) {
        if ( preg_match( $test, $val ) ) {
            exit;
        }
    }

    mail( "contact@jeremyblaze.com", "Contact Form: ".$_POST['name'], $_POST['text'], "From:" . $_POST['email'] );

}
?>

Thanks :)

È stato utile?

Soluzione

Your code should be like this Your are doing wrong way.Add proper subject and message.Please study this link for details.

$subject = 'the subject';
$message = 'Your subject and add phone no here';
mail('contact@jeremyblaze.com', $subject, $message);

Altri suggerimenti

Here is the php mail function page: http://php.net/manual/en/function.mail.php

You cannot add the phone number inside the function like that.

Here is the basic function:

mail(email,subject,body);

You need to add the phone number to the body of the text:

$email = "contact@jeremyblaze.com";
$subject = "Contact Form: ".$_POST['name'];
$body = "From: ".$_POST['email']."\n\r\n\rPhone: ".$_POST['phone']."\n\r\n\r".$_POST['text'];

mail($email,$subject,$body);

You should really look at the documentation on the php site: http://php.net/manual/en/function.mail.php

It will show you how to set additional headers for reply-to and from, etc. But what I gave you should make what you are trying to do.

Just to complement @Mahmood Rehman info, if you want send a HTML e-mail you can do this:

            // From
            $email_from = $vEmail;

            // To
            $to  = 'contact@jeremyblaze.com';

            // Subject
            $subject = $vSubject;

            // HTML Message
            $message = "<html>
            <head>
            <title>Title</title>
            </head>
            <p><b>$vName</b> send the follow message:</p>
            <p><b>Subject:</b> $vSubject</p>
            <p><b>Message:</b> $vMessage </p>
            <p><b>E-mail:</b> $vEmail </p>
            <p><b>Phone:</b> $vPhone </p> 
            </body>
            </html>";

            // To send HTML mail, the Content-type header must be set
            $headers  = "MIME-Version: 1.0\r\n";
            $headers .= "Content-type: text/html; charset=UTF-8\r\n";
            $headers .= "From: $email_from\r\n";

            // Mail it
            mail($to, "=?utf-8?B?".base64_encode($subject)."?=", $message, $headers);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top