Jump to content

Multiple Recipient Contact Form


andrecamp

Recommended Posts

Hi, I tried to make a multiple recipient contact form as shown here.

The email isn't getting sent. What did I do wrong?

 

 

This is the form itself.

<tr>

<td><p>Recipient</p></td>

<td><select name="Recipient" size="1" id="Recipient">

<option value="test1">John Doe 1</option>

<option value="test2">John Doe 2</option>

<option value="test3">John Doe 3</option>

</select>

</td>

</tr>

 

 

This is the processing script.

<?PHP

################################################## ####

# #

# Forms To Go 3.2.5 #

# Bebosoft #

# #

################################################## ####

 

 

 

DEFINE('kOptional', true);

DEFINE('kMandatory', false);

 

 

 

 

error_reporting(E_ERROR | E_WARNING | E_PARSE);

ini_set('track_errors', true);

 

function DoStripSlashes($FieldValue)

{

if ( get_magic_quotes_gpc() ) {

if (is_array($FieldValue) ) {

return array_map('DoStripSlashes', $FieldValue);

} else {

return stripslashes($FieldValue);

}

} else {

return $FieldValue;

}

}

 

#----------

# FilterCChars:

 

function FilterCChars($TheString)

{

return preg_replace('/[\x00-\x1F]/', '', $TheString);

}

 

#----------

# Validate: Email

 

function check_email($email, $optional)

{

if ( (strlen($email) == 0) && ($optional === kOptional) ) {

return true;

} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {

return true;

} else {

return false;

}

}

 

 

 

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];

} else {

$ClientIP = $_SERVER['REMOTE_ADDR'];

}

 

$FTGName = DoStripSlashes( $_REQUEST['Name'] );

$FTGEmail = DoStripSlashes( $_REQUEST['Email'] );

$FTGSubject = DoStripSlashes( $_REQUEST['Subject'] );

$FTGRecipient = DoStripSlashes( $_REQUEST['Recipient'] );

$FTGMessage = DoStripSlashes( $_REQUEST['Message'] );

$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );

 

 

# Fields Validations

 

$ValidationFailed = false;

 

if (!check_email($FTGEmail, kOptional)) {

$ValidationFailed = true;

$FTGEmail_errmsg = 'The email address entered is invalid. ';

$ErrorList .= $FTGEmail_errmsg . '<br/>';

}

 

 

# Include message in error page and dump it to the browser

 

if ($ValidationFailed === true) {

 

$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';

 

$ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Name-->', $FTGName, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Subject-->', $FTGSubject, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Recipient-->', $FTGRecipient, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Message-->', $FTGMessage, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $ErrorPage);

$ErrorPage = str_replace('<!--ERRORMSG:Email-->', $FTGEmail_errmsg, $ErrorPage);

 

 

echo $ErrorPage;

exit;

 

}

# Email to Form Owner

 

$emailSubject = FilterCChars("Mount Olive Contact Form");

 

$emailBody = "Name : $FTGName\n"

. "Email : $FTGEmail\n"

. "Subject : $FTGSubject\n"

. "Recipient : $FTGRecipient\n"

. "Message : $FTGMessage\n"

. "";

 

$emailTo = switch($_POST['Recipient']

{

case "test1":

$email_to = "[email protected]";

break;

case "test2":

$email_to = "[email protected]";

break;

case "test3":

$email_to = "[email protected]";

break;

}

 

$emailFrom = FilterCChars("[email protected]");

 

$emailHeader = "From: $emailFrom\n"

. "MIME-Version: 1.0\n"

. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"

. "Content-transfer-encoding: 8bit\n";

 

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

 

 

# Include message in the success page and dump it to the browser

 

$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';

 

$SuccessPage = str_replace('<!--FIELDVALUE:Name-->', $FTGName, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Subject-->', $FTGSubject, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Recipient-->', $FTGRecipient, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Message-->', $FTGMessage, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $SuccessPage);

 

echo $SuccessPage;

exit;

?>

Link to comment
https://forums.phpfreaks.com/topic/102974-multiple-recipient-contact-form/
Share on other sites

The line via which you set the recipient looks like this:

 

$email_to = "[email protected]";

 

But the line in which you attempt to send the message looks like this:

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

 

You're also doing something strange with that switch statement--I really don't think it'll do what you expect.

$emailTo = switch($_POST['Recipient']

 

Lastly, I don't see where you attempt to have multiple recipients as your post indicated you want to do.

 

$emailTo = "[email protected]";

$emailTo .= "\[email protected]";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

 

 

I actually meant I wanted to have selective recipients. Sorry.

What i mean by selective is that the people can select a department they want the email to be sent to and depending on the department or selection, it chooses an email address to send it to.

if ($Recipient == "test1") {

$emailto = '[email protected]';

} else if ($Recipient == "test2") {

$emailto = '[email protected];

} else if($Recipient == "test3") {

                $emailto = '[email protected]';

        } else {

$errors[] = 'Incorrect Selection #1'; // to prevent people from entering in false e-mail addresses, this provides an error message to be displayed. I used an errors array

}

 

Course you could use a switch statement, but i've never used one before so i'm not familiar with writing them. i use this script on http://moha.iarp.ca/contact.php as you can see i also have another one for choosing a subject.

The form looks like this.

            <form action="contact_sent.php" method="post" name="contact_olive" id="contact_olive">

              <table width="100%" border="0">

                <tr>

                  <td><p>Name</p></td>

                  <td><input name="Name" type="text" id="Name" />

                  </td>

                </tr>

                <tr>

                  <td><p>Email</p></td>

                  <td><input name="Email" type="text" id="Email" />

                  </td>

                </tr>

                <tr>

                  <td><p>Subject</p></td>

                  <td><input name="Subject" type="text" id="Subject" />

                  </td>

                </tr>

                <tr>

                  <td><p>Recipient</p></td>

                  <td><select name="Recipient" size="1" id="Recipient">

                  <option value="spastor">Test1</option>

                  <option value="ypastor">Test2</option>

                  <option value="wmaster">Test3</option>

                  </select>

</td>

                </tr>

                <tr>

                  <td><p>Message</p></td>

                  <td><textarea name="Message" id="Message"></textarea>

</td>

                </tr>

                <tr>

                  <td> </td>

                  <td><input type="submit" name="Submit" value="Submit" /></td>

                </tr>

              </table>

            </form>

 

I edited the form so it would look like this.

 

<?PHP

######################################################

#                                                    #

#                Forms To Go 3.2.5                  #

#            http://www.bebosoft.com/              #

#                                                    #

######################################################

 

 

 

DEFINE('kOptional', true);

DEFINE('kMandatory', false);

 

 

 

 

error_reporting(E_ERROR | E_WARNING | E_PARSE);

ini_set('track_errors', true);

 

function DoStripSlashes($FieldValue)

{

if ( get_magic_quotes_gpc() ) {

  if (is_array($FieldValue) ) {

  return array_map('DoStripSlashes', $FieldValue);

  } else {

  return stripslashes($FieldValue);

  }

} else {

  return $FieldValue;

}

}

 

#----------

# FilterCChars:

 

function FilterCChars($TheString)

{

return preg_replace('/[\x00-\x1F]/', '', $TheString);

}

 

#----------

# Validate: Email

 

function check_email($email, $optional)

{

if ( (strlen($email) == 0) && ($optional === kOptional) ) {

  return true;

} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {

  return true;

} else {

  return false;

}

}

 

 

 

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];

} else {

$ClientIP = $_SERVER['REMOTE_ADDR'];

}

 

$FTGName = DoStripSlashes( $_REQUEST['Name'] );

$FTGEmail = DoStripSlashes( $_REQUEST['Email'] );

$FTGSubject = DoStripSlashes( $_REQUEST['Subject'] );

$FTGRecipient = DoStripSlashes( $_REQUEST['Recipient'] );

$FTGMessage = DoStripSlashes( $_REQUEST['Message'] );

$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );

 

 

# Fields Validations

 

$ValidationFailed = false;

 

if (!check_email($FTGEmail, kOptional)) {

$ValidationFailed = true;

$FTGEmail_errmsg = 'The email address entered is invalid. ';

$ErrorList .= $FTGEmail_errmsg . '<br/>';

}

 

 

# Include message in error page and dump it to the browser

 

if ($ValidationFailed === true) {

 

$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';

 

$ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Name-->', $FTGName, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Subject-->', $FTGSubject, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Recipient-->', $FTGRecipient, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Message-->', $FTGMessage, $ErrorPage);

$ErrorPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $ErrorPage);

$ErrorPage = str_replace('<!--ERRORMSG:Email-->', $FTGEmail_errmsg, $ErrorPage);

 

 

echo $ErrorPage;

exit;

 

}

# Email to Form Owner

 

$emailSubject = FilterCChars("Mount Olive Contact Form");

 

$emailBody = "Name : $FTGName\n"

. "Email : $FTGEmail\n"

. "Subject : $FTGSubject\n"

. "Recipient : $FTGRecipient\n"

. "Message : $FTGMessage\n"

. "";

 

      if ($Recipient == "spastor") {

      $emailto = '[email protected]';

  } else if ($Recipient == "ypastor") {

      $emailto = '[email protected]';

  } else if($Recipient == "wmaster") {

                $emailto = '[email protected]';

        }

 

 

$emailFrom = FilterCChars("[email protected]");

 

$emailHeader = "From: $emailFrom\n"

  . "MIME-Version: 1.0\n"

  . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"

  . "Content-transfer-encoding: 8bit\n";

 

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

 

 

# Include message in the success page and dump it to the browser

 

$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';

 

$SuccessPage = str_replace('<!--FIELDVALUE:Name-->', $FTGName, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Subject-->', $FTGSubject, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Recipient-->', $FTGRecipient, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Message-->', $FTGMessage, $SuccessPage);

$SuccessPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $SuccessPage);

 

echo $SuccessPage;

exit;

?>

 

However, it still didn;t send but the success letter came up after... I am not sure what is going wrong.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.