Jump to content

Emailing


Zepo.

Recommended Posts

This isnt working for some reason, and im not sure if you can email in loops like this......

 

Loop

$emailq=mysql_query("SELECT name,email FROM teams");
while(list($name,$email)=mysql_fetch_row($emailq)){

$email[toname]		="$name";
$email[toemail]		="$email";
$email[subject]		="$send[subject]";
$email[fromname]	="{$_SESSION['rights']}";
$email[fromemail]	="$config[sitemail]";
$email[replyname]	="$name";
$email[replyemail]	="$email";
$email[body]		="$send[body]";

email($email);
$sent.="Sending To $name..........Sent<br />";
}

 

Email Function

//E-Mail Function
function email($email){
mail("$email[toname] <$email[toemail]>","$email[subject]","$email[body]", "From: $email[fromname] <$email[fromemail]>\nReply-To: $email[replyname] <$email[replyemail]>\nContent-type: text/plain\nX-Mailer: PHP/" . phpversion());
}

 

 

No errors.

Link to comment
https://forums.phpfreaks.com/topic/80824-emailing/
Share on other sites

Your function is calling a variable that gets defined in the actual code try:

 

<?php
$emailq=mysql_query("SELECT name,email FROM teams");
function email($email){
mail("$email[toname] <$email[toemail]>","$email[subject]","$email[body]", "From: $email[fromname] <$email[fromemail]>\nReply-To: $email[replyname] <$email[replyemail]>\nContent-type: text/plain\nX-Mailer: PHP/" . phpversion());
}
while(list($name,$email)=mysql_fetch_row($emailq)){

$email[toname]		="$name";
$email[toemail]		="$email";
$email[subject]		="$send[subject]";
$email[fromname]	="{$_SESSION['rights']}";
$email[fromemail]	="$config[sitemail]";
$email[replyname]	="$name";
$email[replyemail]	="$email";
$email[body]		="$send[body]";

email($email);
$sent.="Sending To $name..........Sent<br />";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/80824-emailing/#findComment-410015
Share on other sites

You have alot of code there that would be generating syntax warnings, and also absolutely no error handling.

 

<?php

if ($emailq = mysql_query("SELECT name,email FROM teams")) {
  if (mysql_num_rows($emailq)) {  
    while(list($name,$email)=mysql_fetch_row($emailq)){

      $email['toname']		=$name;
      $email['toemail']		=$email;
      $email['subject']		=$send['subject'];
      $email['fromname']	={$_SESSION['rights'];
      $email['fromemail']	=$config['sitemail'];
      $email['replyname']	=$name;
      $email['replyemail']	=$email;
      $email['body']		=$send['body'];

      if (email($email)) {
        $sent.="Sending To $name..........Sent<br />";
      }
    }
  }
}

 

Next, your email function should look like....

 

<?php

function email($email){
  return mail("{$email['toname']} <{$email['toemail']}>",$email['subject'],$email['body'], "From: {$email['fromname']} <{$email['fromemail']}>\nReply-To: {$email['replyname']} <{$email['replyemail']}>\nContent-type: text/plain\nX-Mailer: PHP/" . phpversion());
}

?>

Link to comment
https://forums.phpfreaks.com/topic/80824-emailing/#findComment-410034
Share on other sites

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.