Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,197,716 members, 7,965,704 topics. Date: Thursday, 03 October 2024 at 07:12 PM

Php Email/database Troubles, Please Help Me Out. - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Php Email/database Troubles, Please Help Me Out. (970 Views)

I Need An Email Database Of Young Working Class Peopl In Lagos / Webmasters Please Help With This Adsense Troubles / Sms To Email/database System (2) (3) (4)

(1) (Reply) (Go Down)

Php Email/database Troubles, Please Help Me Out. by cmon(m): 11:41am On Nov 04, 2008
Now here's the scenario;

I have a database of registered users, with their email addresses. I'm about to create a newsletter system where emails are extracted from the database and a loop is used in sending the emails to the users. I created the script for sending it but it doesn't seem to send the emails. Running through the script, there are no errors so I don't even know how to debug it.

I know there's supposed to be an array involved by it's giving me so much headaches.
Does anybody have a resources for such problems?
Re: Php Email/database Troubles, Please Help Me Out. by cmon(m): 12:18pm On Nov 04, 2008
The problem is solved. It's just the normal "do-While" loop. Thanks for viewing anyway.
Re: Php Email/database Troubles, Please Help Me Out. by yawatide(f): 12:19pm On Nov 04, 2008
It is always good when we solve our own problems - it further cements what we have just learned. wink
Re: Php Email/database Troubles, Please Help Me Out. by cmon(m): 12:57pm On Nov 04, 2008
@yawa, You can say that again grin

However, there's another problem sad

Now I can send the mails to emails in my database. But the server fixes the "from" field of the email sent as 'domain@eclipse.websitewelcome.com'. How do I change this to something like "Our Support Team".

Get what I mean?
Re: Php Email/database Troubles, Please Help Me Out. by kehers(m): 2:29pm On Nov 04, 2008
Create ur own custom From header this way:

$headers = "From: mail@ursite.com\r\n";//or Ur site <mail@ursite.com>
mail($to, $subject, $message, $headers);
But then as I always advise, using mail() inside loops is not always advisable because it opens and closes the mail socket in each call. Use a mail class instead.
Re: Php Email/database Troubles, Please Help Me Out. by Nobody: 7:51am On Nov 05, 2008
kehers:

Create ur own custom From header this way:But then as I always advise, using mail() inside loops is not always advisable because it opens and closes the mail socket in each call. Use a mail class instead.

Thats not true in this case


Here is an excerpt from the phpmailer class

public function Send() {
$header = '';
$body = '';
$result = true;

if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
$this->SetError($this->Lang('provide_address'));
return false;
}

/* Set whether the message is multipart/alternative */
if(!empty($this->AltBody)) {
$this->ContentType = 'multipart/alternative';
}

$this->error_count = 0; // reset errors
$this->SetMessageType();
$header .= $this->CreateHeader();
$body = $this->CreateBody();

if($body == '') {
return false;
}

/* Choose the mailer */
switch($this->Mailer) {
case 'sendmail':
$result = $this->SendmailSend($header, $body);
break;
case 'smtp':
$result = $this->SmtpSend($header, $body);
break;
case 'mail':
$result = $this->MailSend($header, $body);
break;
default:
$result = $this->MailSend($header, $body);
break;
//$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
//$result = false;
//break;
}

return $result;
}




/**
* Sends mail using the $Sendmail program.
* @access public
* @return bool
*/
public function SendmailSend($header, $body) {
if ($this->Sender != '') {
$sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
} else {
$sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
}

if(!@$mail = popen($sendmail, 'w')) {
$this->SetError($this->Lang('execute') . $this->Sendmail);
return false;
}

fputs($mail, $header);
fputs($mail, $body);

$result = pclose($mail);
if (version_compare(phpversion(), '4.2.3') == -1) {
$result = $result >> 8 & 0xFF;
}
if($result != 0) {
$this->SetError($this->Lang('execute') . $this->Sendmail);
return false;
}

return true;
}


the first function ends with an abstraction that should use your chosen method of sending the mail

the second function is just one of the method of sending the mail and you can see where the port was opened in bold

now look at how users are expected to call the class

$mail->Send()

so if you plug that inside a loop, you will still end up opening and closing the sockets with each call to send()
even though the class has been initialized
Re: Php Email/database Troubles, Please Help Me Out. by cmon(m): 12:50pm On Nov 05, 2008
@kehers,

Exactly what I wanted. All problems now solved. Thanks y'all.
Re: Php Email/database Troubles, Please Help Me Out. by kehers(m): 4:15pm On Nov 05, 2008
@webdezzi
Tnx for taking ur time to check out d class nd not just take my word for it. I purposely didnt want to mentn phpmailer but now that u av, fine.
Phpmailer offers 3 methods for mailing- php mail, smtp and sendmail (popening mail path). For loops i'd recommend smtp. But not just that. D SMTPKeepAlive variable should be set to true. Here:

$mail->new phpmailer();
$mail->IsSMTP();//sets method to smtp

$mail->SMTPKeepAlive = true;//dont close socket til socket closing funtn is explicitly called
//, other tns
while(, ){
$mail->send();
$mail->ClearAddresses();//important! prevnts sendg to already mailed addys
}
$mail->SmtpClose();//nw close smtp connectn
let me knw if u com up wit other tns and proof me wrong where neccessary.
Re: Php Email/database Troubles, Please Help Me Out. by Nobody: 7:01pm On Nov 05, 2008
i think i understand what you meant,

if i am correct, the port remains opened and it is kept alive while mail is being sent, that makes more sense

I think if the port is opened from the constructor level, i should still remain opened throughout the lifetime of the object
Re: Php Email/database Troubles, Please Help Me Out. by kehers(m): 8:55am On Nov 06, 2008
if i am correct, the port remains opened and it is kept alive while mail is being sent
Yup, u are correct.
By the way, you can as well tweak the SendmailSend method (function) as well so that the opened sendmail socket is not closed till you do so explicitly. This is done by removing the pclose part and putting that in ur own custom method.
Re: Php Email/database Troubles, Please Help Me Out. by yawatide(f): 1:10pm On Nov 06, 2008
php.net is your friend cool

(1) (Reply)

How Do I Turn My Domain Name To A Blog / Bulk Sms Like Never Before: The Fastest Sms Gateway / How Can I Escape Single Quote In Forms Into Mysql Db

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 43
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.