First i want to start by saying this is my first time with PHP outside of reading.
I am just trying to create a simple contact form that will gather the information and send me the email with the information. Currently my contact page is down and any help would be awesome to get it back up.
Here is my Code:
<?php
if(isset($_POST['Submit'])) {
if(!empty($_POST['CompanyName'])){
if(!empty($_POST['Email']){
$CompanyName = $_POST['CompanyName'];
$PhoneNumber = $_POST['PhoneNumber'];
$Email = $_POST['Email'];
$IndustryType = $_POST['IndustryType'];
$Website = $_POST['Website'];
$Other = $_POST['Other'];
$Comments =$_POST['comments'];
$formcontent ="From: $CompanyName
Message:
Point of Contact: $NameInput
Email: $Email
Industry: $IndustryType $Other
Website: $Website
Comments: $Comments";
$recipient = "keeano@doodleinc.co";
$subject = "Website Contact\ $IndustryType";
$mailHeader = "From $Email
";
echo '<p class="collapse">Thank you for contacting <font color="#709900">Doodle Inc.</font>, someone will contact you within 48 hours.</p>';
mail($Email, $subject, $formcontent);
}
else {
echo 'Please Check required fields with an <font color="#FF0000">* </font>.
If you are exsperiancing any technical issues or have not heard back from us please contact us at <a href="">Techsupport@doodleinc.co</a>';
}
}
}?>
<div class="article">
<h2><span>send us an</span> email ...</h2><div class="clr"></div>
<form name="contact_form" method="post" action="mail.php" onSubmit="return evalid()">
<table border="0">
<tbody class="Form">
<tr>
<td>
<label for="NameInput">Your Name:<font color="#FF0000">*</font></label>
<input id="NameInput" name="NameInput"/>
</td>
</tr>
<tr>
<td>
<label for="CompanyName">Your Company:<font color="#FF0000">*</font></label>
<input id="CompanyName" name="CompanyName"/>
</td>
</tr>
<tr>
<td>
<label id="PhoneNumber" name="PhoneNumber">Phone: </label>
<input id="PhoneNumber" name="PhoneNumber"/>
</td>
</tr>
<tr>
<td>
<label id="Email" name="Email">Email:<font color="#FF0000">*</font></label>
<input id="Email" name="Email" type="email"/>
</td>
</tr>
<tr>
<td>
<label for="Website">Website: </label>
<input id="Website" name="Website"/>
</td>
</tr>
<tr>
<td>
<label for="IndustryType" name="IndustryType">Industrey: </label>
<Select>
.....
<option>Other</option>
</select>
</td>
<?php
if($IndustryType == "Other")
echo '<div id="Other">
<td>
<label for="=Other" class="collapse">Other: </label><input id="Other" name="Other" class="collapse"/>
</div>
<br/>
<br/>
</td>
?>
</tr>
<br/>
<br/>
<br/>
<br/>
<tr>
<th><p><b>What interests you, broadly speaking?</b></p></th>
</tr>
<tr><td>
<input type="checkbox">Web Design/Development</input>
</td></tr>
<tr><td>
<input type="checkbox">Social Media</input>
</td></tr>
<tr><td>
<input type="checkbox">Mobile Presence</input>
</td></tr>
<tr><td>
<input type="checkbox">Online Advertising</input>
</td></tr>
<tr><td>
<input type="checkbox">Search Engine Optamization</input>
</td></tr>
<tr><td>
<input type="checkbox">eCommerce</input>
</td></td>
<tr>
<th><div class="spacer"></div></th>
</tr>
<tr><td>
<label for="comments"><b>Your Ideas to Life? (How can we help you?)</b></label><br/>
<textarea id="comments" name="comments" style="margin: 2px; height: 137px; width: 437px;"></textarea></td></tr><br/>
<tr>
<td><input type="button" name="Submit" value="Submit" align="middle" /></td>
</tr>
</tbody>
</table>
</form>
I have tried putting the email function in a separate file called mail.php but that didn't work so i inline it into the HTML and the page fails on load.
I was also unsuccesfull in getting XAMPP to work locally as well.
I know its something could even be something small, but i am hoping to figure out what it is and learning in the process. Any docs or web sites you prefer to aid me would be awesome as well.
any help is appreciated!
Use the library phpmailer to send emails. You can find some tutorials about how use it
You need to set up SMTP in your php.ini
file. If you don't know what to set the SMTP as, then do a Google search for your email carrier's SMTP. Also set the port.
Your SMTP and port should be set according to your email carrier. So if you use Gmail, than set these settings like this:
SMTP = smtp.gmail.com
smtp_port = 25
Your form's action attribute is set to action="mail.php
. Make sure that your code is in that file. Finally, restart apache. If you are still receiving errors then try this:
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
$headers .= 'From: ' . $youremail. "
";
mail($Email, $subject, $formcontent);
Note: the $youremail
variable is the email address you use and the email address that you set you SMTP settings for.
Final steps: Go here and download the sendmail package and extract it in your xampp root directory. Edit these lines:
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourname@gmail.com
auth_password=gmailpassword
force_sender=yourname@gmail.com
Next open the xampp php.ini file again and edit the line that says sendmail_path
. Make sure it is not commented.
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Restart apache.
Your code is returning this error:
Parse error: syntax error, unexpected '{' in /var/www/crm.demotores.6.5.11/site/test.php on line 5
You should change in your php.ini - display_errors = On
to see what's going on with your script.
The ")" was missed in this line. After fix it, you have:
Parse error: syntax error, unexpected ''<div id="Other">' (T_ENCAPSED_AND_WHITESPACE) in /var/www/crm.demotores.6.5.11/site/test.php on line 72