I am trying to adapt the receiver of a message depending on the value of a select input in my webform. I have a select input that is labelled "object" and that features 3 different values (contact/support/marketing). If the user select "support", I want to send the user's message to a specific mail address that is linked to the object chosen. So I wrote the following code: My html form:
<p>
<label for="formObject">Object*</label>
<select name="formObject" id="formObject" data-validation="required">
<option value="information-products">Information on products and services</option>
<option value="quotation">Quotation request</option>
<option value="support">Support</option>
</select>
</p>
My PHP treatment is:
// CHOICE OF EMAIL ADDRESS
if ($_POST["formObject"] == "information-products") {
$mailReveiver = "mailAddress1@gmail.com";
} elseif($_POST["formObject"] == "quotation") {
$mailReveiver = "mailAddress2@gmail.com, mailAddress3@gmail";
} else {
$mailReveiver = "mailAddress4@gmail.com, mailAddress5@gmail.com";
}
/** code used to create the message */
/** function to send the mail */
if (mail($mailReveiver, $sujet, $message, $header)) {
echo "<p class='big-big-size'>Thank you for your message!</p>";
}
When I try to run this code on my webserserver, the message is sent only when I select "Information on products and services" in the form. In this case, I receive the message in the correct mailbox. Moreover, I tried to "echo" the content of my variable named $mailReceiver instead of using the mail function. The value of the variable in this case is correct.
Can someone help me and tell me if I have made some mistakes in my code ? Thank you for reading me ! Olivier
Aucun commentaire:
Enregistrer un commentaire