NameSilo

Contact Form Help

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
Watch

DJL2K

Pimp Master MEstablished Member
Impact
0
Okay, so I've got a contact form for my portfolio. The code looks alright but the form won't send the emails that are submitted
contact.php
PHP:
<?php
$youremail = "[email protected]";
$subject = $_POST['subject'];
$thankyou = "Thank you. Your Email has been sent; I'll try to respond ASAP.";

while($_POST['submit']) {
	if( $email == "" ) {
		echo("<tr><td colspan='2' style='text-align:text-align:center; '>No email address added. Please go back.<br/></td></tr>");
		}
	elseif($name == "") {
		echo("<tr><td colspan='2' style='text-align:text-align:center; '>No name added. Please go back.<br/></td></tr>");
		}
	elseif($message == "") {
		echo("<tr><td colspan='2' style='text-align:text-align:center; '>No message added. Please go back.<br/></td></tr>");
		}
	else {
		$msg = ereg_replace("\\\'", "'", $message);
		$msg = ereg_replace('\\\"', "\"", $msg);
		$message1 = "from: $name<br />email: $email<br />message:<br />$msg1";

		mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
		echo("<tr><td colspan='2' style='text-align:text-align:center; '>$thankyou</td></tr>");
		}
	}
?>
</table>
</form>
Click here to see what is doing
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You don't need a while loop, you can use the isset() function with an if statement. For example:

Code:
if(isset($_POST['submit']))
{
     //Other code
}

Now the problem lies in the mail function. You need to specify the user's email address, not yours.

Code:
mail([b]$youremail[/b], $subject, $msg, "From: $email\r\nReply-to: $email\r\n");

The bolded part should not be $youremail, but the variable $email (or $_POST['email']) since that represents the contacter's email address.
 
0
Close
The script is supposed to send it to him. He has it right.

PHP:
<?php
$youremail = "[email protected]";
$subject = $_POST['subject'];
$thankyou = "Thank you. Your Email has been sent; I'll try to respond ASAP.";

if($_POST['submit']) {
    $email = $_POST['email'];
    $name = $_POST['name'];
    $message = $_POST['message'];
    if( $email == "" ) {
        echo("<tr><td colspan='2' style='text-align:text-align:center; '>No email address added. Please go back.<br/></td></tr>");
        }
    elseif($name == "") {
        echo("<tr><td colspan='2' style='text-align:text-align:center; '>No name added. Please go back.<br/></td></tr>");
        }
    elseif($message == "") {
        echo("<tr><td colspan='2' style='text-align:text-align:center; '>No message added. Please go back.<br/></td></tr>");
        }
    else {
        $msg = ereg_replace("\\\'", "'", $message);
        $msg = ereg_replace('\\\"', "\"", $msg);
        $message1 = "from: $name<br />email: $email<br />message:<br />$msg1";
        $headers = 'From: ' . $email . "\r\n" .
                   'Reply-To: ' . $email . "\r\n"
        mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
        echo("<tr><td colspan='2' style='text-align:text-align:center; '>$thankyou</td></tr>");
        }
    }
?>
</table>
</form>
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back