Jump to content

Recommended Posts

I have a contact form on my site.... I'm trying to have the user be able to select an interest from a select field which will then email to a certain person, the mail however is not being sent... any help?

 

<?php

$EmailTo = "email@server.com";
$Subject = "Web Contact";
$Name = Trim(stripslashes($_POST['Name'])); 
$Interests = Trim(stripslashes($_POST['Interests'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

if ($Interests == "General Information") {
$EmailTo = "email1@server.com";
}
else ($Interests == "Acupuncture") {
$EmailTo = "email2@server.com";
}
else ($Interests == "Massage Therapy") {
$EmailTo = "email3@server.com";
}
else ($Interests == "Cranio-Sacral Therapy") {
$EmailTo = "email4@server.com";
}

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Interests: ";
$Body .= $Interests;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$Email>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/149817-simple-mail-form-not-sending/
Share on other sites

heres a script i use for sending emails that always works for me

 

<?php

//// Email the new password to the person.
$Name = ""; //senders name
$email = ""; //senders e-mail adress
$recipient = ""; //recipient


   $mail_body = " EMAIL MESSAGE GOES HERE";


$subject = " EMAIL SUBJECT GOES HERE "; //subject

$headers = "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
$headers .= 'MIME-Version: 1.0' . "\r\n";
//$headers .= "Reply-to: <support@click4web.co.il>\r\n";


ini_set('sendmail_from', ' SENDERS EMAIL '); //Suggested by "Some Guy"


mail($recipient, $subject, $mail_body, $headers); //mail command 

 

hope this helps!

Sure, here is the form code:

 

<div id="contact-area">

		<form method="post" action="contactengine.php">
			<label for="Name" id="Name">Name:</label>
			<input type="text" name="Name" />

			<label for="Interests" id="Interests">Subject:</label>
			<select id="select1" name="select1">
				<option value="em1">General Information</option>
				<option value="em2">Acupuncture</option>
				<option value="em3">Massage Therapy</option>
				<option value="em4">Cranio-Sacral Therapy</option>
			</select><br />					

			<label for="Email" id="Email">Email:</label>
			<input type="text" name="Email" />

			<label for="Message" id="Message">Message:</label><br />
			<textarea name="Message" rows="20" cols="20"></textarea>

			<input type="submit" name="submit" value="Submit" class="submit-button" />
		</form>

		<div style="clear: both;"></div>

</div>

 

heres a script i use for sending emails that always works for me

 

<?php

//// Email the new password to the person.
$Name = ""; //senders name
$email = ""; //senders e-mail adress
$recipient = ""; //recipient


   $mail_body = " EMAIL MESSAGE GOES HERE";


$subject = " EMAIL SUBJECT GOES HERE "; //subject

$headers = "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
$headers .= 'MIME-Version: 1.0' . "\r\n";
//$headers .= "Reply-to: <support@click4web.co.il>\r\n";


ini_set('sendmail_from', ' SENDERS EMAIL '); //Suggested by "Some Guy"


mail($recipient, $subject, $mail_body, $headers); //mail command 

 

hope this helps!

 

The only problem is I want to be able to send to different email addresses depending on the option chosen in the select field..

the problem is this line i think

 

<select id="select1" name="select1">

 

you called it select1 but in the php you are trying to get Interests.  try changing to

 

<select id="Interests" name="Interests">

 

 

 

I did see that and I changed it - now it just brings up a blank page and still no emails sent..

change

 

<option value="em1">General Information</option>
<option value="em2">Acupuncture</option>
<option value="em3">Massage Therapy</option>
<option value="em4">Cranio-Sacral Therapy</option>

 

to

 

<option value="General Information">General Information</option>
<option value="Acupuncture">Acupuncture</option>
<option value="Massage Therapy">Massage Therapy</option>
<option value="Cranio-Sacral Therapy">Cranio-Sacral Therapy</option>

Actually I think maybe they do support PHP .. this is from their site..

 

Our Microsoft .NET 3.5 hosting plans (now including Service Pack 1) are ideal for developing dynamic websites and robust applications, and includes database support, PHP 5, ecommerce tools, and more.

change

 

<option value="em1">General Information</option>
<option value="em2">Acupuncture</option>
<option value="em3">Massage Therapy</option>
<option value="em4">Cranio-Sacral Therapy</option>

 

to

 

<option value="General Information">General Information</option>
<option value="Acupuncture">Acupuncture</option>
<option value="Massage Therapy">Massage Therapy</option>
<option value="Cranio-Sacral Therapy">Cranio-Sacral Therapy</option>

 

Did that, didn't send any email..

They sent me this in terms of sending php email on their server

 

Subject: Sending mail using PHP
Article #534

Here is an example script for sending out mail using php:

<?
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');

// Set parameters of the email
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";

// Mail function that sends the email.
mail($to,$subject,$message,$headers);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.