PHP send to a friend script, troubleshooting...
02-03-2009, 02:25 PM
|
PHP send to a friend script, troubleshooting...
|
Posts: 66
|
Hello,
I have a sight issue I was hoping you all could please shed light to. I am trying to create a "send to a friend" popup page where someone fills out my form, and then the email would send out to others with a URL.
I have set up the form, and looked on the internet how this is done, but after I click "send" on my page, there is some wacky script afterward and it doesn't look like it's working.
This is my first time dealling with PHP, and am a little stumped on how to get this working. Can someone PLEASE steer me in the right direction, or let me know how to get it to work, I would really appreciate it. Here is the actual page: http://www.iongeo.com/innovation_tes...riend_test.php
Here is my form code:
PHP Code:
<form action="tellck.php" method="post"> <p>Your Name <input type="text" name="y_name" value=""> <br> </p> <p>Your Email <input type="text" name="y_email" value=""> <br> </p> <p>Your Friend's Name <input type="text" name="f_name" value=""> <br> </p> <p>Friend's Email <input type="text" name="f_email" value=""> <br> </p> <p>Message <textarea name="y_msg" cols="60″ rows="6″></textarea> <br> <br> <input type="submit" name="Send" value="Send" /> <input type="reset" name="Clear" value="Clear"> </center> </p> </form>
Here is my php script (on a different php page)
PHP Code:
<? $status = "OK"; $msg=""; $y_email=$_POST['y_email']; $y_name=$_POST['y_name']; $f_email=$_POST['f_email']; $f_name=$_POST['f_name']; $y_msg=$_POST['y_msg']; if(substr_count($y_email,"@") > 1 or substr_count($f_email,"@") > 1){ $msg .="Use only one email address<BR>"; $status= "NOTOK"; } if (!stristr($y_email,"@") OR !stristr($y_email,".")) { // checking your email $msg .="Your email address is not correct<BR>"; $status= "NOTOK";} if (strlen($y_name) <2 ) { // checking your name $msg .="Please enter your name<BR>"; $status= "NOTOK";} if (!stristr($f_email,"@") OR !stristr($f_email,".")) { // checking friends email $msg .="Your Friends address is not correct<BR>"; $status= "NOTOK";} if (strlen($f_name) <2 ) { // checking freinds name $msg .="Please enter your friend's name<BR>"; $status= "NOTOK";} if (strlen($y_msg) <2 ) { // checking Message details $msg .="Please enter your message details<BR>"; $status= "NOTOK";} if($status=="OK"){ // all validation passed /////////// Sending the message starts here ////////////// $ref=@$HTTP_REFERER; /////Message at the top of the page showing the url//// $header_message = "Hi $f_name n Your friend $y_name requested you to visit this page http://www.piticstyle.com"; /// Body message prepared with the message entered by the user //// $body_message =$header_message."n".$y_msg."n"; $body_message .=""; //// Mail posting part starts here ///////// $headers=""; //$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; // Un comment the above line to send mail in html format $headers4=$y_email; // Change this to change from address $headers.="Reply-to: $headers4n"; $headers .= "From: $headers4n"; $headers .= "Errors-to: $headers4n"; $subject="Request to visit URL"; mail($f_email,$subject,$body_message,$headers); ////// Mail posting ends here /////////// echo "<center><font face='Verdana' size='2' color=green>Thank You, Your message was send to $f_name</font></center>"; //////////// Sending the message ends here ///////////// }else{// display the error message echo "<center><font face='Verdana' size='2' color=red>$msg</font></center>"; } ?>
Thanks,
Mike
|
|
|
|
02-03-2009, 02:41 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 51
|
Ran your script.... with the funky output
Code:
1 or substr_count($f_email,"@") > 1){ $msg .="Use only one email address
"; $status= "NOTOK"; } if (!stristr($y_email,"@") OR !stristr($y_email,".")) { // checking your email $msg .="Your email address is not correct
"; $status= "NOTOK";} if (strlen($y_name) <2 ) { // checking your name $msg .="Please enter your name
"; $status= "NOTOK";} if (!stristr($f_email,"@") OR !stristr($f_email,".")) { // checking friends email $msg .="Your Friends address is not correct
"; $status= "NOTOK";} if (strlen($f_name) <2 ) { // checking freinds name $msg .="Please enter your friend's name
"; $status= "NOTOK";} if (strlen($y_msg) <2 ) { // checking Message details $msg .="Please enter your message details
"; $status= "NOTOK";} if($status=="OK"){ // all validation passed /////////// Sending the message starts here ////////////// $ref=@$HTTP_REFERER; /////Message at the top of the page showing the url//// $header_message = "Hi $f_name n Your friend $y_name requested you to visit this page http://www.piticstyle.com"; /// Body message prepared with the message entered by the user //// $body_message =$header_message."n".$y_msg."n"; $body_message .=""; //// Mail posting part starts here ///////// $headers=""; //$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; // Un comment the above line to send mail in html format $headers4=$y_email; // Change this to change from address $headers.="Reply-to: $headers4n"; $headers .= "From: $headers4n"; $headers .= "Errors-to: $headers4n"; $subject="Request to visit URL"; mail($f_email,$subject,$body_message,$headers); ////// Mail posting ends here /////////// echo "Thank You, Your message was send to $f_name"; //////////// Sending the message ends here ///////////// }else{// display the error message echo "$msg"; } ?>
you first might want to replace the "OR"'s with the correct operator || (two pipes)
Then retry the script
|
|
|
|
02-03-2009, 07:11 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 66
|
Thanks for the prompt reply,
I've replaced the "or" words with || but it still doesn't appear to be working.
As I've mentioned before, I have never really made anything in php, and my form document is in HTML, but I read that it doesn't really make a difference as long as it compiles and brings in the correct external PHP document.
If anyone knows how I could get my php script to work or know what I am doing wrong, that would be lovely.
Thanks so much,
Mike
Last edited by Mikeface; 02-03-2009 at 07:23 PM..
|
|
|
|
02-03-2009, 11:44 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 203
Name: Andy
Location: N.Ireland
|
I think it may be just a case of your server not supporting PHP short tags.... try replacing all your <? with <php?
|
|
|
|
02-04-2009, 11:45 AM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 66
|
Wow, thanks so much for your response Andy! I was fumbling around with that for a while yesterday.
That looks like it did the trick, after I hit send, the "you have just sent an email to __" message is displayed... I have tested it out and haven't received any emails after clicking send, but it might just take a while, or it might not be sending them at all, I have no idea.
If anyone has time, please test it out yourself, or perhaps look into what could be a problem, http://www.iongeo.com/innovation_tes...riend_test.php
Many thanks to everyone who has helped me out.
Last edited by Mikeface; 02-04-2009 at 11:55 AM..
|
|
|
|
02-04-2009, 03:03 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 1,605
|
I sent myself one. Will ley you know if I get it.
edit: 4 hours later and still no email. As i posted in another thread here tonight:
Quote:
|
The IP number (black-listed), the lack of reverse dns, the like of x-mailer headers within the email are all things that can prevent mail from being delivered.
|
Last edited by colbyt; 02-04-2009 at 07:46 PM..
|
|
|
|
02-05-2009, 03:02 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 66
|
Weak.
I'm not sure what the problem is then. I contacted my server and they told me that they will soon stop supporting PHP, so I will have to figure out how to do this using .asp instead.
|
|
|
|
02-05-2009, 05:34 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 250
|
They said they will stop supporting php ? weird
You can also do this with simple javascript as well
Just have a google around for it there's loads. 
|
|
|
|
02-05-2009, 07:41 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 66
|
That javascript is easy, unfortunately, the people I am working with would like it to be a popup page on our server where users input fields rather than an email that comes up.
I just do what they tell me. Thanks so much for everyone's responses, this is getting really frustrating.
|
|
|
|
02-06-2009, 11:57 AM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 250
|
Mike I am looking for something similar to this for my website and was actually playing around with that exact script last night.
However i came across something that is so easy to use you may like it or you may not.
Its only a few lines of code that you add.
Try it out. www.sharethis.com
Ive tried your script and it just comes up with
Quote:
Your email address is not correct
Please enter your name
Your Friends address is not correct
Please enter your friend's name
|
The emails ended with @whatever.com so dont know how it worked that one out!
This may help! http://css-tricks.com/nice-and-simple-contact-form/
Im going to give that one a whirl myself
Hope to help
|
|
|
|
02-06-2009, 04:07 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 66
|
Thanks for the links mofo,
I am working on some other things right now, but will give your links a shot this weekend and figure it out.
After I figure out my options, I will let everyone know.
Thanks,
Mike
|
|
|
|
02-06-2009, 05:23 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 1,605
|
Guys why are you wasting your time with these scripts?
mailto will do everything you need for a TAF form and offers the assurance that the email addresses won't be mis-used?
Here is the basic code all html:
PHP Code:
<a href="mailto:Enter your Friends email?subject=Whatever subject you want &body= Whatever pre-populated message you want.">Tell a friend</a>
You can see a working, image enhanced version by viewing any joke or cartoon at photopun*com.
True it won't be a hotlink unless the sender uses send html email as their default but how many don't use that?
|
|
|
|
02-06-2009, 06:04 PM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
|
Quote:
Originally Posted by Mikeface
Weak.
I'm not sure what the problem is then. I contacted my server and they told me that they will soon stop supporting PHP, so I will have to figure out how to do this using .asp instead.
|
An ASP one isn't a problem
One here and I use one on http://www.candsdesign.co.uk/
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
|
|
|
|
02-08-2009, 01:15 AM
|
Re: PHP send to a friend script, troubleshooting...
|
Posts: 203
Name: Andy
Location: N.Ireland
|
To be honest, it looks like they have sendmail deactived on their php.ini
I would look at using a different hosting company if I where you, it seems odd that they would stop supporting an open source product and going instead for a pricey, dare I say it 'microsoft' product.... hmmmmmmm
|
|
|
|
|
« Reply to PHP send to a friend script, troubleshooting...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|