logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 05-05-2015, 02:31 PM   #1
jacob1986
 
Join Date: May 2015
Posts: 20
Default Contact Form using .php

I have written some php code for my contact form, most of the message does works. The problem I have is this - when I receive the message I see the recipient's email address but no name, moreover; when I changed the code I could see the recipient's name but no email address?

I have three text boxes (name, email and message) in my html webpage, but cannot seem to get the php working.

<?php

$from="reply.info@websiteinfotest.ninja";
$email="info@websiteinfotest.ninja";
$to ="info@websiteinfotest.ninja";
$subject=$_POST['Subject'];
$from=$_REQUEST["from"];
$message=$_POST['Message'];


mail ( $email, $subject, $message, "From:".$from);


Print "Your Message has been sent";



?>
jacob1986 is offline   Reply With Quote
Old 05-06-2015, 12:54 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

Quote:
I have three text boxes (name, email and message)
so these will be $message=$_POST['Message'];,$message=$_POST['from];, and possiibly $message=$_POST[name'];

you have define $from twice so that is wrong. You could compile the message do this
Code:
$from="reply.info@websiteinfotest.ninja";
$email="info@websiteinfotest.ninja";
$to ="info@websiteinfotest.ninja";
$subject=$_POST['Subject'];

$message=$_POST['Message']. $_POST['from].$_POST[name'];


mail ( $email, $subject, $message, "From:".$from);


Print "Your Message has been sent";
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-06-2015, 06:25 AM   #3
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

you will also need yo validate this to prevent spamming
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-06-2015, 06:27 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

an example copy pasted
Code:
<?php
 
    if (isset($_POST['Submit'])) {
 
        if ($_POST['name'] != "") {
            $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
            if ($_POST['name'] == "") {
                $errors .= 'Please enter a valid name.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your name.<br/>';
        }
 
        if ($_POST['email'] != "") {
            $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
            }
        } else {
            $errors .= 'Please enter your email address.<br/>';
        }
 
        if ($_POST['homepage'] != "") {
            $homepage = filter_var($_POST['homepage'], FILTER_SANITIZE_URL);
            if (!filter_var($homepage, FILTER_VALIDATE_URL)) {
                $errors .= "$homepage is <strong>NOT</strong> a valid URL.<br/><br/>";
            }
        } else {
            $errors .= 'Please enter your home page.<br/>';
        }
 
        if ($_POST['message'] != "") {
            $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
            if ($_POST['message'] == "") {
                $errors .= 'Please enter a message to send.<br/>';
            }
        } else {
            $errors .= 'Please enter a message to send.<br/>';
        }
 
        if (!$errors) {
            $mail_to = 'me@somewhere.com';
            $subject = 'New Mail from Form Submission';
            $message  = 'From: ' . $_POST['name'] . "\n";
            $message .= 'Email: ' . $_POST['email'] . "\n";
            $message .= 'Homepage: ' . $_POST['homepage'] . "\n";
            $message .= "Message:\n" . $_POST['message'] . "\n\n";
            mail($to, $subject, $message);
 
            echo "Thank you for your email!<br/><br/>";
        } else {
            echo '<div style="color: red">' . $errors . '<br/></div>';
        }
    }
?>
 
<form name="form1" method="post" action="form-email.php">
Name: <br/>
<input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" /><br/><br/>
Email Address: <br/>
<input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><br/>
Home Page: <br/>
<input type="text" name="homepage" value="<?php echo $_POST['homepage']; ?>" size="50" /> <br/><br/>
Message: <br/>
<textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-06-2015, 02:46 PM   #5
jacob1986
 
Join Date: May 2015
Posts: 20
Default

I tried to use the 'example copy' but no messages were sent to my email client? I will explain my procedure(s) for working in Dreamwever (php files) later for you.

All I really want to know is the correct was in which I can see all the information from my 'contact form' in my email client. When I receive the message from my contact form - I can see the recipients email address (where subject should be) and I can see 'To' which is my email address and the message itself - but no actual name of the correspondents or a 'from tag' i.e. the person's email address?

Moreover; when I receive a 'normal' email to my email client I can see subject, as well as the 'from tag' - the recipients email address and the 'To' which is my email address and below all this is the actual message.
jacob1986 is offline   Reply With Quote
Old 05-06-2015, 02:59 PM   #6
jacob1986
 
Join Date: May 2015
Posts: 20
Default

New document >> php >> delete html code >> code view: paste ‘example copy’ >> edit line 42 - $mail_to = 'me@somewhere.com'; >> save as mail script >> new html document >> insert form code in between the body tags >> save as contact >> upload mail script and then copy the location >> insert location of mail script into ‘action’ and save >> upload contact.


But as I said nothing was happening, I'm probably doing something wrong?
jacob1986 is offline   Reply With Quote
Old 05-07-2015, 12:52 AM   #7
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

ah, sorry i was a bit busy, i should have explained better. i will re do for you later.
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-07-2015, 01:42 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

ok just tested it , i missed that there was an action to another page.
This is a one page with action set to itself, i also removed the url field with its validation so to make it what you wanted. you can of course separate the php and html and change the action.
Code:
<?php
 
    if (isset($_POST['Submit'])) {
 
        if ($_POST['name'] != "") {
            $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
            if ($_POST['name'] == "") {
                $errors .= 'Please enter a valid name.<br/><br/>';
            }
        } else {
            $errors .= 'Please enter your name.<br/>';
        }
 
        if ($_POST['email'] != "") {
            $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
            }
        } else {
            $errors .= 'Please enter your email address.<br/>';
        }
 
      
        if ($_POST['message'] != "") {
            $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
            if ($_POST['message'] == "") {
                $errors .= 'Please enter a message to send.<br/>';
            }
        } else {
            $errors .= 'Please enter a message to send.<br/>';
        }
 
        if (!$errors) {
            $mail_to = 'me@somewhere.com';
            $subject = 'New Mail from Form Submission';
            $message  = 'From: ' . $_POST['name'] . "\n";
            $message .= 'Email: ' . $_POST['email'] . "\n";
            $message .= "Message:\n" . $_POST['message'] . "\n\n";
            mail($to, $subject, $message);
 
            echo "Thank you for your email!<br/><br/>";
        } else {
            echo '<div style="color: red">' . $errors . '<br/></div>';
        }
    }
?>
 
<form name="form1" method="post" action=  "">
Name: <br/>
<input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" /><br/><br/>
Email Address: <br/>
<input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><br/>

Message: <br/>
<textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>
<br/>
<input type="submit" name="Submit" />
</form
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-07-2015, 08:34 PM   #9
jacob1986
 
Join Date: May 2015
Posts: 20
Default

Foremost: thank-you for helping me.

I am going to start again from scratch (building a form and php in Dreamweaver) then I will write the php code again from (as I said) scratch... I will ask for help in the next days to fathom the code operations (argument and so forth).

Once again thank-you.
jacob1986 is offline   Reply With Quote
Old 05-08-2015, 01:07 AM   #10
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

no problem. try not to rely on dreamweaver php code though, not always best in my experience
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 09:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com