[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-18-2006, 12:10 PM   #1 (permalink)
Pimp Master M
 
Join Date: Apr 2006
Posts: 51
54.30 NP$ (Donate)

DJL2K is on a distinguished road


Contact Form Help

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 Code:
<?php
$youremail
= "matt@matt-license.com";
$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
DJL2K is offline  
Old 08-18-2006, 01:47 PM   #2 (permalink)
NamePros Member
 
Man In The Box's Avatar
 
Join Date: Aug 2006
Location: Canada
Posts: 34
104.00 NP$ (Donate)

Man In The Box is an unknown quantity at this point


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($youremail, $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.
Man In The Box is offline  
Old 08-18-2006, 01:59 PM   #3 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
The script is supposed to send it to him. He has it right.

PHP Code:
<?php
$youremail
= "matt@matt-license.com";
$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>
Dan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:27 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85