 |
 |
 |
 |
 |
| Author |
Message |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
Hey i sat down to have a look at this script today and found whr the error is. When i replaced
mail($mail, $subject, $message, $headers)
with
mail($mail, $subject, "test mail", $headers)
presto, then the email goes thru!!
So the problem lies in sending html emails. Since the short story / long story of the article is obviously goin to be in html there will need to be a little fixing in the mail-a-friend file. I figured out that the fixing should have be done in the $headers area but have no idea what to do. Cud any body help me out with it pls??
The current &headers section in the file is as follows
 |  | $headers = 'From: '.$mail_from."\n";
$headers .= 'Reply-to: '.$mail_from."\n";
$headers .= 'Return-Path: '.$mail_from."\n";
$headers .= 'Message-ID: <'.md5(uniqid(time())).'@'.$_SERVER['SERVER_NAME'].">\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/plain'."\n";
$headers .= 'Content-transfer-encoding: 7bit'."\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
$headers .= 'X-Priority: 3'."\n";
$headers .= 'X-MSMail-Priority: Normal'."\n"; |
Thanx
|
|
| Sun Sep 17, 2006 6:54 am |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
Just to make things easier, this is my whole code
 |  |
<?php
if($_POST['dosend'] == "yes"){
//Config subject
$subject = "Interesting article";
//Config message
$message = "Hello {friend},\n\n";
$message .= "I found an interesting article:\n";
$message .= "Please check it out yourself: {story}\n\n";
$message .= "Best regards,\n{sendername}";
//Config mail
$mail_from = $_POST['sendermail'];
//
$friend = $_POST['recipientname'];
$mail = $_POST['recipientmail'];
$sendername = $_POST['sendername'];
$error = false;
if($friend == "" or $mail == ""){
$error = "Error! At least one field is empty. Please go back and fill out all the fields.";
}
$message = str_replace("{friend}", $friend, $message);
$message = str_replace("{story}", $story, $message);
$message = str_replace("{sendername}", $sendername, $message);
$headers = 'From: '.$mail_from."\n";
$headers .= 'Reply-to: '.$mail_from."\n";
$headers .= 'Return-Path: '.$mail_from."\n";
$headers .= 'Message-ID: <'.md5(uniqid(time())).'@'.$_SERVER['SERVER_NAME'].">\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/plain'."\n";
$headers .= 'Content-transfer-encoding: 7bit'."\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
$headers .= 'X-Priority: 3'."\n";
$headers .= 'X-MSMail-Priority: Normal'."\n";
if(mail($mail, $subject, $message, $headers)){
echo "Thank you.<br />";
echo "The message was sent to ".$friend." (".$mail.")<br /><br />";
echo '<a href="javascript:window.close();">Close window</a>';
}
else echo $error;
}
else{
?>
<form action="" method="post">
<table>
<tr><td>Senders Name:</td><td><input type="text" name="sendername"></td></tr>
<tr><td>Senders E-mail:</td><td><input type="text" name="sendermail"></td></tr>
<tr><td>Recipient's Name:</td><td><input type="text" name="recipientname"></td></tr>
<tr><td>Recipient's E-mail:</td><td><input type="text" name="recipientmail"></td></tr> <tr><td colspan="2"><input type="submit" value="E-Mail Article"></td></tr>
<input type="hidden" name="dosend" value="yes">
</table>
</form>
<?
}
?> |
|
|
| Sun Sep 17, 2006 7:03 am |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
That's working: mail($mail, $subject, "test mail", $headers);
That's not working: mail($mail, $subject, $message, $headers);
Right?
Then $headers is not the problem but $message. There must be something in the mail body which causes the it to get filtered out.
|
|
| Sun Sep 17, 2006 2:39 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
 |  | There must be something in the mail body which causes the it to get filtered out. |
well what kind of thing cud cause it to filter out?? i only have a normal news article in it. But ofcourse its in html. I just did a bit chekin around and got a small lead.
cud it be something wrong here:-
$headers .= 'Content-type: text/plain'."\n";
Here i tryied changing it to text/html but still didnt work. May be we'r missing something.
Check out the following coding. Its used to form mail some html content and its working perfectly. Can ve try to integrate it directly into the header of the tell-a-friend script??
 |  | $headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: Info <info@mydomain.com>\r\n";
$headers .= "From: Info\r\n";
$email="info@mydomain.com";
if(mail($email,$subject,$message,$headers))
{
header("Location: thankyou.htm");
} |
|
|
| Sun Sep 17, 2006 6:08 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
Simply replace the headers with your new ones.
|
|
| Sun Sep 17, 2006 7:50 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
I'm stumped it still doesnt work.. Ok atleast i found one error. Although i was trying to email the full story ihad not updated it in the template file. so i updated it as following replacing the url={link=home/post} with ?story={full-story}
 |  | <img src="images/icon-tellfriend.gif" alt="Print" width="18" height="16" border="0" /><a onclick="window.open('{cutepath}/mail_to_friend.php?story={full-story}','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no,width=370,height=285')" href="javascript:void(0);" title="E-Mail Article."><b>E-Mail Article</b></a> |
But this gives a error in the web page it self. How shoud i capture the full story??
|
|
| Tue Sep 19, 2006 5:01 pm |
|
 |
siamend

Joined: 17 Oct 2005 Posts: 70 Location: Deutschland |
|
|
|
I have acted and sayd "thank you"
but with Error
 |  |
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Programme\xampp\htdocs\nigargel\r\mail_to_friend.php on line 37
Thank you.
The message was sent to tenha test (info@germeser.net)
|

_________________ ..:::: Germeser :::.. |
|
| Tue Sep 19, 2006 10:13 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
This script only works on your webhost. It doesn't work on localhost.
|
|
| Wed Sep 20, 2006 2:26 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
fi-dd, any help with my query?? how to capture the the title and the full story of the article with a link to the page pls??
thanx
|
|
| Wed Sep 20, 2006 4:12 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
The apostrophe or any other special sign in your full story is breaking the javascript.
So you have to create a new tag for your template: {full-story-mail}
And in inc/show.news.php you have to replace this new tag with the full story which doesn't have an apostrophe.
So find this:
 |  | $output = str_replace('{full-story}', run_filters('news-entry-content', $row['full']), $output); |
and add below:
 |  | $output = str_replace('{full-story-mail}', str_replace("'", "\'", $row['full']), $output); |
Please notice how I replaced the apostrophe with an escaped apostrophe \'.
In mail_to_friend.php you have to replace the escaped apostrophe \' with an apostrophe.
-------------------------------------
Another possibility is to create a form in your template which leads to mail_to_friend.php. This way you don't have to handle the special signs from above.
 |  | <form action="mail_to_friend.php" method="post">
<input type="submit" value="Mail to friend">
<input type="hidden" name="story" value="{full-story}">
</form> |
I didn't test this possibility.
|
|
| Thu Sep 21, 2006 6:35 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
thanx so much for ur response fi-dd!! It gave me a couple of new avenues to look into. I came accross a coupl of qeustions when i was trying to do this.
1. If i create a new tag {full-story-mail} in the shownews.php, wudn't it, regardless of whether the article is goin to be emailed or not, create a duplicate of the full-story in memory?? And download it into the user machine evrytime the fullstory link is clicked and therefore increase download tme?? I guess this wudnt be much of a problem if the full-story contained only text, but what if there was a lot of images in the full-story?? 'm not sure if this is a really dumb question but i just thought it might happen so...
2. Are there any other characters other than the apostrophe that cud cause it be terminated??
3. If i'm using the form method, is there any way i cud open mail-to-frien.php in a separate small window rather than it opening in the same window it self??
Thanx for ur help fi-dd..
|
|
| Sat Sep 23, 2006 6:14 am |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
 |  | 1. If i create a new tag {full-story-mail} in the shownews.php, wudn't it, regardless of whether the article is goin to be emailed or not, create a duplicate of the full-story in memory?? And download it into the user machine evrytime the fullstory link is clicked and therefore increase download tme?? I guess this wudnt be much of a problem if the full-story contained only text, but what if there was a lot of images in the full-story?? 'm not sure if this is a really dumb question but i just thought it might happen so... |
Yes, it would duplicate the memory. But you only have the html code in the variables and not the whole picture. So even a 2 MB picture is only some twenty bytes in the source code.
 |  | 2. Are there any other characters other than the apostrophe that cud cause it be terminated?? |
I only know of the apostrophe as this is used in the javascript code to enclose a variable. You have to find out yourself by starting with a text without any special characters and then adding them step-by-step.
 |  | 3. If i'm using the form method, is there any way i cud open mail-to-frien.php in a separate small window rather than it opening in the same window it self?? |
I think adding target="blank" to the <form> tag should help.
|
|
| Sat Sep 23, 2006 2:13 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
Fi-dd, after spending so much of time on this i'm ready to giv up now. I am receiving the email but without the story id. No matter how much i tried i dont seem to have a solution But i have one question to ask.
In ur original tell-a-friend script, though u r submitting ?url={link=home/post} from the template, u have not attempted to capture this data into a $url variable in the script itself!! Is this a error or is that the way it should be. Cos i used a
 |  | $url = $_POST['url']; |
snippet in the mail-a-friend.php file before the
 |  | $message = str_replace("{url}", $url, $message); |
But still dont have any luck. I no its not being captured cos i'm echoing both $message and $url in the thank you part of the script but the $url is returning empty
Ok, now to the second part of my post..
I thought of a possible work around for the whole scenario. But i need ur help with this and i really hope u wud have some time to spare. Its not something to create from scratch but rather a modification to a existing plugin.
Here goes...
You already have the newsletter plugin with which u allow the system users to select a news item and mail it to the whole database of email addresses.
ok, can we have a small script like this --> when the viewer clicks on the tell a friend link it submits {id} to the tell-a-friend.php file. The tell-a-friend.php file then retrives the news item (title & full story) from the database and also gets the user inputs for the friends email address and mails it to that address! Just like a newsletter being sent!!
What do you think?? Is it a big job?? I really hope i'm not asking for too much 
Last edited by ksen on Sun Sep 24, 2006 5:39 pm; edited 1 time in total |
|
| Sun Sep 24, 2006 3:53 pm |
|
 |
ksen

Joined: 04 Jun 2006 Posts: 142
|
|
|
|
Fi-dd, Just for ur infomation..
* My template has the follwing code for the email article part.
 |  | <a onclick="window.open('{cutepath}/mail_to_friend.php?url={link=home/post}','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes,width=370,height=285')" href="javascript:void(0);" title="E-Mail Article."><b>E-Mail Article</b></a> |
* Then once i viewed my www.mydomain.com/fullstory.php?id=1015 i viewed its source and i have this bit code near the email article option.
 |  | <a onclick="window.open('http://www.mydomain.com/cn/mail_to_friend.php?url=http://www.mydomain.com/fullstory.php?id=1013','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=o,width=370,height=285')" href="javascript:void(0);" title="E-Mail Article."><b>E-Mail Article</b></a> |
Which means the data is being properly transfered to the tell-a-friend.php file but the tell-a-friend.php is not capturing it!!
The tell-a-friend.php code is as follows.
 |  | <?php
if($_POST['dosend'] == "yes"){
//Config subject
$subject = "Interesting article";
//Config message
$message = "Hello {friend},<br /><br />";
$message .= "I found an interesting article :<br />";
$message .= "Please check it out yourself: {url}<br /><br />";
$message .= "<br /><br />Best regards,<br />{sendername}";
//Config mail
$mail_from = $_POST['sendermail'];
//
$friend = $_POST['recipientname'];
$mail = $_POST['recipientmail'];
$sendername = $_POST['sendername'];
$url = $_POST['url'];
$error = false;
if($friend == "" or $mail == ""){
$error = "Error! At least one field is empty. Please go back and fill out all the fields.";
}
$message = str_replace("{friend}", $friend, $message);
$message = str_replace("{url}", $url, $message);
$message = str_replace("{sendername}", $sendername, $message);
$headers = 'From: '.$mail_from."\n";
$headers .= 'Reply-to: '.$mail_from."\n";
$headers .= 'Return-Path: '.$mail_from."\n";
$headers .= 'Message-ID: <'.md5(uniqid(time())).'@'.$_SERVER['SERVER_NAME'].">\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Content-type: text/html'."\n";
$headers .= 'Content-transfer-encoding: 8bit'."\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
$headers .= 'X-Priority: 3'."\n";
$headers .= 'X-MSMail-Priority: Normal'."\n";
if(mail($mail, $subject, $message, $headers)){
echo "Thank you.<br />";
echo "The message was sent to ".$friend." (".$mail.")<br /><br />";
echo $message;
echo "<br/>";
echo $url;
echo '<a href="javascript:window.close();">Close window</a>';
}
else echo $error;
}
else{
?>
<form action="" method="post">
<table>
<tr><td>Senders Name:</td><td><input type="text" name="sendername"></td></tr>
<tr><td>Senders E-mail:</td><td><input type="text" name="sendermail"></td></tr>
<tr><td>Recipient's Name:</td><td><input type="text" name="recipientname"></td></tr>
<tr><td>Recipient's E-mail:</td><td><input type="text" name="recipientmail"></td></tr> <tr><td colspan="2"><input type="submit" value="E-Mail Article"></td></tr>
<input type="hidden" name="dosend" value="yes">
</table>
</form>
<?
}
?> |
You may notice that i have included $url = $_POST['url']; into my code but this still doesnt work. I'm wondering wether this is because ?url is being submitted only from the fullstory.php to the tell-friend.php but not from the there onwards when the form is being submitted!! If u get what i mean!!
|
|
| Sun Sep 24, 2006 5:04 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
$url = $_POST['url']; is the best and safest way to get the variable. I was lazy in my script, but it should work too.
In your case (you are not using rufus) you simply have to submit the article's ID using {id} in your template:
 |  | <a onclick="window.open('{cutepath}/mail_to_friend.php?article_id={id}','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes,width=370,height=285')" href="javascript:void(0);" title="E-Mail Article."><b>E-Mail Article</b></a> |
And in mail_to_friend.php you have to build the link to your article using the article_id variable:
 |  | $message = str_replace({url}, 'http://www.yourdomain.com/fullstory.php?id='.$_POST['article_id'], $message); |
Or you can get the full story by writing something like this:
 |  | include('./head.php');
$story = reset(
$sql->select(array(
'table' => 'story',
'where' => array("post_id = ".$_POST['article_id'])
)));
$message = str_replace({full-story}, replace_news('admin', $story['full']), $message); |
|
|
| Mon Sep 25, 2006 6:36 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|
 |
 |
 |
|