bmobm Posted October 9, 2010 Share Posted October 9, 2010 Ok, this is the situation, I have a form to email script installed on my website, (im not the best with PHP but im learning) I managed to adapt the main contact form to meet my needs however i am now having a few probs, basically the script i am using is IBDhost Contact Form. The basic code consits of 4 fields, name field, email field, subject dropdown box and message text box. On my site i need to adapt the form to incorporate additional fields, which are for the first form..... name field (compulsory), COMPANY name field (non compulsory), valid email (compulsory), contact number (compulsory), Department dropdown box ( i want this to determin what mailbox the message gets sent to, so rather than just 1 email address for all messages to go to, i want the user to determine where the email goes through a variety of email address options) and the main message text box. The second difference i need is for a different page, using the same form, but with different fields, Name field (compulsory), Contact Number (compulsory) email address (compulsory) message text box area(non compulsory) and an attachment upload field. I need the attachment upload to be able to do 1 of 2 things, either send the attachment along with the email, OR upload the email to a directory on my server BUT have the form details include a link to the form when i receive it. basically it will be used for C.V uploads for jobs. The code i am using is shown below ... FORM CODE: <form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> Full Name: <br /> <input type="text" name="visitor" size="35" /> <br /> Valid Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> Contact Number:<br /> <input type="text" name="visitorcontactnumber" size="35" /> <br /> <!-- BELOW IS WHERE I WANT THE USER TO BE ABLE TO PICK A DEPARTMENT BUT INSTEAD OF THAT BEING THE ATTENTION TO SUBJECT, I WANT IT TO SEND IT TO THE RELEVENT EMAIL ADDRESS --> Attention:<br /> <select name="attn" size="1"> <option value=" Administration ">Administration </option> <option value=" Existing Clients ">Clients (existing) </option> <option value=" New Client Enquiry ">Clients (new) </option> <option value=" Director Of Sales And Marketing ">Sales Director </option> <option value=" General Enquiries ">General Enquiries </option> <option value=" Site Support ">Site Support </option> <option value=" Recruitment ">Recruitment </option> <option value=" Web Master ">Webmaster </option> </select> <br /><br /> Message (please include company details if a client): <br /> <textarea name="notes" rows="6" cols="60"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form> SENDEAIL.php code <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $visitorcontactnumber = $_POST['visitorcontactnumber']; $attn = $_POST['attn']; $notes = $_POST['notes']; if (eregi('http:', $notes)) { die ("Do NOT try that! ! "); } if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { echo "<h2>Use Back - Enter valid e-mail</h2>\n"; $badinput = "<h2>Your message was NOT submitted</h2>\n"; echo $badinput; die ("Go back! ! "); } if(empty($visitor) || empty($visitormail) || empty($visitorcontactnumber) || empty($notes )) { echo "<h2>Use Back - fill in all fields</h2>\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $attn; $notes = stripcslashes($notes); $message = " $todayis [EST] \n Attention: $attn \n Message: $notes \n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n Browser Info: $httpagent \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; mail("me@myemail.net", $subject, $message, $from, $visitorcontactnumber); ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) <br /> Attention: <?php echo $attn ?> <br /> Message:<br /> <?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?> <br /> <?php echo $ip ?> <br /><br /> <a href="contact.php"> Back </a> </p> the only problem i have with the form i have adapted so far is that all the details are coming through on the message to my email apart from the additional field (contact number) so im obviously missing something there as well. I would really appreciate any help. And i hope in the future i can assist someone on here too. Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/ Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 $visitorcontactnumber doesn't belong there. It belongs in the message body. mail("me@myemail.net", $subject, $message, $from, $visitorcontactnumber); Usage: mail('to', 'subject', 'body', 'additional headers') Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120521 Share on other sites More sharing options...
bmobm Posted October 9, 2010 Author Share Posted October 9, 2010 But thats wat i already have isnt it? $from = "From: $visitormail\r\n"; mail("md@tlkdirect.net", $subject, $message, $from, $visitorcontactnumber); ?> Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120536 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 No, you're trying to insert a telephone number as an email header. Things like From:, Cc:, Bcc:, and the like are email headers. You need to concatenate the contact number to the body of the email so it becomes part of $message. Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120537 Share on other sites More sharing options...
bmobm Posted October 9, 2010 Author Share Posted October 9, 2010 Ok, i got it now, ive fixed it, apart from 1 more problem with this perticular form, im now getting an error of "Warning: mail() expects at most 5 parameters, 6 given in /home/tlkdirec/public_html/sendeail.php on line 148" I know its because ive added an extra field but i cannot for the life of me find where i change the perameters from 5 to 6. Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120549 Share on other sites More sharing options...
Pikachu2000 Posted October 9, 2010 Share Posted October 9, 2010 Post the current code you're using. Something seems to have gone awry . . . Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120552 Share on other sites More sharing options...
bmobm Posted October 9, 2010 Author Share Posted October 9, 2010 New code: <?php$ip = $_POST['ip'];$httpref = $_POST['httpref'];$httpagent = $_POST['httpagent'];$visitor = $_POST['visitor'];$visitormail = $_POST['visitormail'];$visitorcontactnumber = $_POST['visitorcontactnumber'];$companyname = $_POST['companyname'];$attn = $_POST['attn'];$notes = $_POST['notes'];if (eregi('http:', $notes)) {die ("Do NOT try that! ! ");}if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))){echo "<h2>Please Use Back Button - Enter valid e-mail</h2>\n";$badinput = "<h2>Your message was NOT submitted</h2>\n";echo $badinput;die ("Go back! ! ");}if(empty($visitor) || empty($visitormail) || empty($visitorcontactnumber) || empty($notes )) {echo "<h2>Use Back - fill in all fields</h2>\n";die ("Use back! ! ");}$todayis = date("l, F j, Y, g:i a") ;$attn = $attn ;$subject = $attn;$notes = stripcslashes($notes);$message = " $todayis [EST] \nAttention: $attn \nMessage: $notes \nFrom: $visitor ($visitormail)\nContact Number: $visitorcontactnumber \nCompany Name: $companyname \nAdditional Info : IP = $ip \nBrowser Info: $httpagent \nReferral : $httpref \n";$from = "From: $visitormail\r\n";mail("me@mymail.net", $subject, $message, $from, $visitorcontactnumber, $companyname);?><p align="center">Date: <?php echo $todayis ?><br />Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )<br />Company Name: <?php echo $companyname ?><br />Contact Number: <?php echo $visitorcontactnumber ?><br />Attention: <?php echo $attn ?><br />Message:<br /><?php $notesout = str_replace("\r", "<br/>", $notes);echo $notesout; ?><br /><?php echo $ip ?><br /><br />Your message has been submitted. Please click here to return to the previous page<br /> <a href="contact.php"> Back </a></p> Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120557 Share on other sites More sharing options...
jcbones Posted October 9, 2010 Share Posted October 9, 2010 This is all you need: mail("me@mymail.net", $subject, $message, $from); Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120559 Share on other sites More sharing options...
bmobm Posted October 9, 2010 Author Share Posted October 9, 2010 Thats it........ Yay lol. perfect. all working perfect now, thank you very much for your help. i have just 1 more question for you. ive been searching all last night for the answer but i need it in laymans terms, i need to add an attachment feield to the form, so it does either 1 of 2 things, first i would like it to attach a file (C.V for employment) and send it with the email to me or it should upload it to my server and a link to the attachment in the email i receive so i can go and retreive it. can you help me with this please??? Quote Link to comment https://forums.phpfreaks.com/topic/215486-contact-form-issues/#findComment-1120562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.