Jump to content

Another mailing list issue


twilitegxa

Recommended Posts

Here is the error I'm receiving:

 

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:\wamp\www\files\sendmymail.php on line 46

 

How do I adjust these settings? Or is there something else I need to do? Here is the code:

 

<?php
if ($_POST[op] != "send") {
//haven't seen the form, so show it
print "
<HTML>
<HEAD>
<TITLE>Send A Newsletter</TITLE>
</HEAD>
<BODY>
<h1>Send A Newsletter</h1>
<form method=\"post\" action=\"$_SERVER[php_SELF]\">
<p><strong>Subject:</strong><br />
<input type=\"text\" name=\"subject\" size=30></p>
<p><strong>Mail Body:</strong><br />
<textarea name=\"message\" cols=50 rows=10 

wrap=virtual></textarea>
<input type=\"hidden\" name=\"op\" value=\"send\">
<p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p>
</form>
</body>
</html>";

} else if ($_POST[op] == "send") {
//want to send form; so check for required fields
if (($_POST[subject] =="") || ($_POST[message] == "")) {
header("Location: sendmymail.php");
exit;
}

//connect to database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("smrpg",$conn) or doe(mysql_error());

//get emails from subscribers list
$sql = "select email from subscribers";
$result = mysql_query($sql,$conn) or die(mysql_error());

//create a From: mailheader
$headers = "From: Your Mailing List <[email protected]\n";

//loop through results and send mail
while ($row = mysql_fetch_array($result)) {
set_time_limit(0);
$email = $row['email'];
mail("email", stripslashes($_POST[subject]),
stripslashes($_POST[message]), $headers);
print "newsletter sent to $email<br />";
}
}
?>

 

There doesn't appear to be any problems with the code itself, but just in case. I receive the error message but it also will say:

 

newsletter sent to [email protected]

(that's the e-mail address I have in the database), but when I check my e-mail to see if the test worked, but it doesn't actually send, which is I guess why I get the error. Can anyone tell me what to change and how?

Link to comment
https://forums.phpfreaks.com/topic/121107-another-mailing-list-issue/
Share on other sites

As far as i know the from email , must be registered on the host , unless you set the SMTP email somewhere else , for example by using PHPmailer.

 

So you need to change the from email to one that is set up on the host.

 

Well not necessarily...but some mail providers like Yahoo! will flag the message as spam if the sending email is not hosted on the domain. They do a reverse DNS lookup on the sending address. So yeah...there's a chance the ISP or mail providers will flag as spam.

I think it is , thats why the SMTP error is appearing, as when i tried sending emails via mail(); with my hotmail address, it wouldnt send, i contacted my host and they said it has to be one registered on the server.

 

So i used PHPmailer, and set it in the SMTP settings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.