Link to my site: http://www.ilnika.com
SMF version: SMF 2.0 RC3
TP version: TP ver 1 beta 5
Theme name and version: Curve Default
Browser Name and Version: Firefox 3.6.8
Mods installed:
1. Sitemap 2.1.2
2. Custom Form Mod 1.
3. Aeva Media 1.3a
4. Pretty URLs 1.0
6. Facebook_Like v.1.2 1.
7. AutoKeywords 1.
8. Team Page 3.5.
9. TinyPortal 1.
11. Google Tagged 1.
12. ENotify 1.0.
13. Users Online Today 1.5.
14. Aeva Media 1.1b
15. Redirection Topics 1.
16. FaceBook Style NavBar (FBSNB) 1.0.
17. Contact Page 2.0.
18. SA Affiliates 3.3.5
Related Error messages: none
Hi there ppl. I would like to know. Is there a way that i can add a block to the homepage of my website where users can enter their email address and click subscribe then the website sends a email from that email address to the mailing-subscribe addresss?? if its possible please.
Subscribe to what? How are you going to store the email addresses? Can you give more details on what you're trying to do?
i have a mailing list application on my server. so the person that wants to join the mailing list should send an email from theyr address to the mailing-subscribe@xxxxxxx to be a part of the list. So i thought if i could have a block where they only enter their email address and subscribe that it would work. Ideas are welcome.
Does the email have to have a specific format in order for your list server to consider it a subscription email?
Well, this should do something like what you're asking. You can change the "to" address for your list server subscription email, and you can change the subject for the email in case your list server requires a certain subject line for a subscription. The $title variable is what the text right above the textbox is so you can customize what you want it to say. It should show a message box with errors if the submission email textbox is empty or doesn't have a valid email in it. A success message if the email was sent. Works on my server, so let me know if you have any problems.
/**** Start Configuration Options ****/
$to = 'listaddress@domain.com';
$subject = 'Subscription to List';
$title = 'Subscribe to our list';
/**** End Configuration Options ****/
/**** Do not edit below this line unless you know what you're doing ****/
if (isset($_POST['esubmit'])) {
$userEmail = $_POST['user_mail'];
$messages = array();
$send = false;
if (empty($userEmail)) {
$messages[] = 'Sorry but the Address cannot be left blank.';
}
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $userEmail)){
$messages[] = 'Please enter a valid email.';
}
else {
$send = true;
}
if ($send) {
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: '. $to . "\r\n";
$headers .= 'From: '. $userEmail . "\r\n";
$body = 'User subscribed to your list: '. $userEmail;
$sentMail = mail($to, $subject, $body, $headers);
if ($sentMail) {
$messages[] = 'The email address ['.$userEmail.'] has been successfully subscribed.';
}
else {
$messages[] = 'An error has occurred. Please try again. If the error persists please contact the Administrator.';
}
}
if (!empty($messages)) {
echo '
<div style="border: 2px dashed red; padding: 5px; font-size: 10px; color: red;">
<h3 color: red;"> Message: </h3>
<ul style="padding: 0 0 0 20px; margin: 0;">';
foreach ($messages as $message) {
echo '<li>', $message ,'</li>';
}
echo '
</ul>
</div>';
}
}
echo '
<center>
<p>', $title ,'</p>
<form method="post" action="', $_SERVER['REQUEST_URI'] ,'">
<input type="text" name="user_mail" size="20" />
<input type="submit" name="esubmit" value="Subscribe" />
</form>
</center>';
The block looks good. But only problem is that it doesn't send a mail. But that is the type of thing that i want.
And also there is nothing in the error log.
Are you getting a success or error message from the code after you click subscribe?
It could be that your server is marking it as spam too. When you use the mail function like this, it would normally appear as if your server is sending the email because it's using the mail agent on the server to create the email. In order to get the email to appear as if the user sent it from their address I'm forcing the header to say it was from the address that the user input into the textbox. Try a couple of different emails besides your list email in the $to variable to see if you successfully get an email at different addresses.
The block shows that it was added. i tried a couple of email addresses. still nothing.
Well you'll need to look at your apache error log, and possibly your maillog to see if there is any output to help us see why you're server isn't working with this. I've tested this on my server and it is working just fine.
I guess we can test something as well. Put this in a file called mail_test.php, and put the file in the root of your SMF folder. Inside the file paste this code:
<?php
$email = $_GET['email'];
if(mail($email, 'Mail test', 'If you received this then the test passed 12345ééé54321 123456789àèéìòùÈ987654321'))
echo 'We sent the email<br /><br />';
else
echo 'We failed to send the email<br /><br />';
?>
Now open your browser and hit the file using a link like this:
http://www.yoursite.com/forum/mail_test.php?email=youremail@yoursite.com
This will send an email without forcing the header changes I had. If it works, then we know your server doesn't like something in our other code.
Wow this actually works. Just tested it out.... Pretty neat I have to say... You never fail to impress IchBin.... Good stuff
Keep up the great work