MacGuyUK Posted June 24, 2010 Share Posted June 24, 2010 Could someone please tell me what I may be doing wrong with the "$ccAddress" on my PHP form code (see below)? Although it does send a copy (cc) to the sender('emai'), it seems to generate a "suspicious" header as the email always gets redirected to both recipients' junk folder. Any help would be much appreciated. Thank you. <?php $Company = $_REQUEST['company']; $Email = $_REQUEST['email']; $Date = $_REQUEST['date']; $PO = $_REQUEST['po']; $Message = $_REQUEST['message']; $Item1 = $_REQUEST['qty1']; $Item2 = $_REQUEST['qty2']; $Item3 = $_REQUEST['qty3']; $Item4 = $_REQUEST['qty4']; $Item5 = $_REQUEST['qty5']; /*Sending Email*/ $to = $_POST['to']; $ccAddress=$_POST['email']; $subject = "Form"; $message = " Company = $company Email = $email Date = $date PO = $po Message = $message Item1 = $qty1 Item2 = $qty2 Item3 = $qty3 Item4 = $qty4 Item5 = $qty5"; $from = "$email"; if(mail($to, $subject, $message, $headers, "From: $from")) echo "Thank you for submitting your form"; else echo "Mail send failure - message not sent"; ?> Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/ Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 First, what does your form look like? You're using values from both $_REQUEST & $_POST which can be problematic. Use either $_GET (if the values are on the URL) or $_POST. Next, you're using the mail function incorrectly. The format is <?php mail($to,$subject,$body,$headers,$extra_headers); ?> You have $headers in the call, but you don't define it anywhere. The fifth parameter that you're using -- the "From" line should be in the $headers variable. You're not using the CC line anywhere. That should also be in the $headers variable. Ken Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/#findComment-1076611 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 I'm not sure how it sends anything at all. Most of the variables are undefined. $Company != $company, $po != $PO $email != $Email, etc. Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/#findComment-1076635 Share on other sites More sharing options...
MacGuyUK Posted June 24, 2010 Author Share Posted June 24, 2010 Hi kenrbnsn & Pikachu2000, Please see below for the actual form, which works perfectly, except for sending the forms to the junk folder, which I am assuming is caused by the wrong header. kenrbnsn : should I replace $-REQUEST for $_POST throughout? Will it still work? Should the $headers look like this: $headers = "From: $from\r\n"; $headers = "CC: $email\r\n"; <form action="formsend.php" method="post" enctype="multipart/form-data" name="form" class="style63" id="form"> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="4%" valign="middle" nowrap="nowrap"><div align="right">1.</div></td> <td width="27%" valign="middle" nowrap="nowrap">Company</td> <td width="52%"><input name="company" type="text" class="style63" id="company" /> </td> </tr> <tr> <td valign="middle"><div align="right">2.</div></td> <td valign="middle">Email <span class="style174 style185">(*Required)</span></td> <td><input name="email" type="text" class="style63" id="email" value="" size="40" /></td> </tr> <tr> <td valign="middle"><div align="right">3.</div></td> <td valign="middle">Date</td> <td><input name="date" type="text" class="style63" id="date" /></td> </tr> <tr valign="middle"> <td colspan="3" class="style63"><hr width="100%" size="1" noshade="noshade" /></td> </tr> <tr> <td valign="middle" class="style63"><input name="qty 1" type="text" class="style63" id="qty 1" size="3" maxlength="3" /></td> <td colspan="2" valign="middle">Item 1</td> </tr> <tr> <td valign="middle" class="style63"><input name="qty 2" type="text" class="style63" id="qty 2" size="3" maxlength="3" /></td> <td colspan="2" valign="middle">Item 2</td> </tr> <tr> <td valign="middle" class="style63"><input name="qty 3" type="text" class="style63" id="qty 3" size="3" maxlength="3" /></td> <td colspan="2" valign="middle">Item 3</td> </tr> <tr> <td valign="middle" class="style63"><input name="qty 4" type="text" class="style63" id="qty 4" size="3" maxlength="3" /></td> <td colspan="2" valign="middle">Item 4</td> </tr> <tr> <td valign="middle" class="style63"><input name="qty 5" type="text" class="style63" id="qty 5" size="3" maxlength="3" /></td> <td colspan="2" valign="middle">Item 5</td> </tr> <tr> <td colspan="3" valign="top" class="style63"><hr width="100%" size="1" /></td> </tr> <tr> <td colspan="3" valign="top" class="style63"><div align="center" class="bodytext_lg"><strong>Please use the drop-down menu below to select your Recipient then click the Submit button</strong></div></td> </tr> </table> <label></label> <div align="center"> </div> <label class="style63"></label> <label> <div align="center"> <select name="to"> <option value="[email protected]">Recipient1</option> <option value="[email protected]">Recipient2</option> <option value="[email protected]">Recipient3</option> </select> <input name="Submit" type="submit" class="style63" id="Submit" value="Submit" /> <br /> <br /> </div> </label> </form> Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/#findComment-1076661 Share on other sites More sharing options...
MacGuyUK Posted June 24, 2010 Author Share Posted June 24, 2010 Thank you kenrbnsn! Following your advice, I amended my code to this: $headers = "From: $email\r\n"; $headers .= "CC: $email\r\n"; if(mail($to, $subject, $message, $headers, $extra_headers)) and it seems to be working. Please let me know if you think this is still wrong. Thank you. Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/#findComment-1076673 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 If you're not using the $extra_headers variable, you can leave it out of the function call. Ken Link to comment https://forums.phpfreaks.com/topic/205739-ccaddress-produces-junk-header/#findComment-1076674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.