Question about my Mail Code..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alfugazi
Forum Newbie
Posts: 2
Joined: Wed Dec 09, 2009 2:34 pm

Question about my Mail Code..

Post by alfugazi »

Ok here's the deal. I have a contact form that people use to email a client on a site.
There are a few fields on the page that are required to be input - Name, Email Address, Phone Number, and of course the Message itself.

This script works great but whats happening is when the email message arrives at its destination, it says it is coming from a default mail server from network solutions (where site is hosted). I'd like to see the inputted email address come up in the Network Solutions email program as the from email address as opposed to the network solutions default mail server email.

Can anyone help me out with this? I am very new to PHP and any help would be greatly appreciated.

<?php
$show_confirmation = false;
if(isset($_POST['action']) && $_POST['action'] == 'send') {

/* Set this variable to the email address you want the form to be submitted to: */
$to_email = 'info@ccestatemanagement.com';


/* Set this variable to be the Subject of the email that is received with the form submission. */
$subject = "CCEM Contact Form Submission";

/* Set this to be the text you want displayed to the user after they submit the form: */
$confirmation_text = "Your information has been sent. Thank You.";


$isOk=true;
if(!isset($_POST['name']) || preg_match("/^\s*$/", $_POST['name']) ) {
$bad_name=true;
$isOk = false;
}
if(!isset($_POST['email']) || preg_match("/^\s*$/", $_POST['email']) ) {
$bad_email=true;
$isOk = false;
}
if(!isset($_POST['phone']) || preg_match("/^\s*$/", $_POST['phone']) ) {
$bad_phone=true;
$isOk = false;
}

if($isOk) {
$message = "Contact Form Submission Details:\n==================================\n";
$message .= "Name:\t".$_POST['name']."\n";
$message .= "Email:\t".$_POST['email']."\n";
$message .= "Phone:\t".$_POST['phone']."\n";

if(isset($_POST['message'])) {
$message .= "Message:\t".$_POST['message']."\n";
}

mail($to_email, $subject, $message);
}

$show_confirmation = $isOk;
}
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Question about my Mail Code..

Post by requinix »

Take a look at the $additional_headers argument to mail. Check the examples and user comments.
alfugazi
Forum Newbie
Posts: 2
Joined: Wed Dec 09, 2009 2:34 pm

Re: Question about my Mail Code..

Post by alfugazi »

Tas...I understand the concept but dont really understand the syntax. Not sure how to take something a user inputs as an email address and then set a variable to that email address. I am learning still.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Question about my Mail Code..

Post by AbraCadaver »

Code: Select all

$headers = 'From: ' . $_POST['name'] . '<' . $_POST['email'] . '>' . "\r\n";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply