d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With Html / Php - Contact Form > Pretty Basic
Add Reply New Topic New Poll
Member
Posts: 10,304
Joined: Mar 31 2008
Gold: 2,500.00
Trader: Trusted
Oct 2 2014 06:15am
This would be pretty basic for any developer, however I am a newbie and am having issues.

1. I need a functional yet pretty simple contact form for a site.

-company
-name
-email
-phone
-comments

- Submit button

- php that actually sends an email with entered information ( And makes sure fields are correct )

I can just copy any contact template from the net, but I am having an issue making it send the email.
Perhaps this is because I don't know jack about php.

Any help, thoughts, advice, code?

Willing to donate some pixels for help.


St.
Retired Moderator
Posts: 18,570
Joined: Feb 27 2004
Gold: 11,858.00
Trader: Trusted
Oct 2 2014 06:20am
It is probably because you aren't using the correct headers when using the PHP Mail() function.

They can be tricky and might be more beneficial for you to simply use a prebuilt library like PHPMailer.

If you need help, depending on the requirements, I can. Just pm me.
Retired Moderator
Posts: 21,073
Joined: Apr 7 2008
Gold: 5,135.90
Trader: Trusted
Oct 2 2014 12:08pm
Hopefully this helps. You will have to change some of the information but that is a really simple form.


Code

<!--Php to send email and return message to user -->
<?php

//standard fields
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

//information to send email
$to = 'emailname@mail.name';
$subject = 'Subject line here';
$from = "From $name";

//email content
$body = "From: $name\n
Email: $email\n
Message: $message";

//variable to confirm form is valid.
$allValid = True;

//regex
$validEmail = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";

$validName = "([a-zA-Z]){2,}";

//if submit pressed
if ($_POST['submit']) {

//check all forms valid, false if they are not.
if(!eregi($validName,$name)){
$allValid = False;
echo 'Houston, we have a problem';
}

if(!eregi($validEmail,$email)){
$allValid = False;
echo 'Houston, we have a problem';
}

if($message == ''){
$allValid = False;
echo 'Houston, we have a problem';

}
//all valid, send the email.
if($allValid){
if (mail ($to, $subject, $body, $from)) {
echo 'Success';
$name = '';
$email = '';
$city = '';
$phone = '';
$message = '';
}
else {
echo 'Houston, we have a problem';
}
}
}
?>
<!-- end php-->

<div id="contactForm">
<form method="post" action="yourpagename.php">
<div class="row alt">
<div class="t">Name: <span class="required">*</span></div>
<div><input type="text" name="name" value="<?php echo $name; ?>"/></div>
</div>

<div class="row">
<div class="t">Email Address: <span class="required">*</span></div>
<div><input type="email" name="email" value="<?php echo $email; ?>"/></div>
</div>

<div class="row alt">
<div class="t">Message: <span class="required">*</span></div>
<div><textarea name="message"><?php echo $message; ?></textarea></div>
</div>

<div class="row">
<div class="submit"><input type="submit" id="send" name="submit" value="Send Inquiry" /></div>
</div>
</form>
</div>
Member
Posts: 31,806
Joined: Jan 22 2008
Gold: 2,235.56
Oct 2 2014 02:41pm
If you still need help lmk via pm :)
Member
Posts: 10,304
Joined: Mar 31 2008
Gold: 2,500.00
Trader: Trusted
Oct 5 2014 11:21am
Thanks guys but David took care of it for me.

I appreciate your time and I will let you know if I need any further help!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll