Foros del Web » Programando para Internet » PHP »

usar vector para cc en PHPMailer

Estas en el tema de usar vector para cc en PHPMailer en el foro de PHP en Foros del Web. El problema que tengo es que quiero recorrer un vector que contien la lista del to y del cc pero em da un error simpled ...
  #1 (permalink)  
Antiguo 18/02/2011, 11:03
 
Fecha de Ingreso: octubre-2009
Mensajes: 19
Antigüedad: 14 años, 6 meses
Puntos: 0
Busqueda usar vector para cc en PHPMailer

El problema que tengo es que quiero recorrer un vector que contien la lista del to y del cc pero em da un error simpled e invalid adress. los datos del to y cc son tomados de uan caja de texto. Si alguien tiene una idea de como hace el addcc dinamico sin usar base de datso. se los agradeceria un monton.

Código PHP:
<?php 
$a
=$_POST['title'];
$b=$_POST['to'];
$c=$_POST['cc'];
$d=$_POST['dear'];
$f=$_POST['url'];
$g=$_POST['IPB'];
$h=$_POST['IPRM'];
$i=$_POST['IPRF'];
$j=$_POST['MRMF'];
$k=$_POST['GC'];
$l=$_POST['OM'];
$m=$_POST['DD'];
$file=file_get_contents('mail_base.html');
$file=str_replace('#title#',$a,$file);
$file=str_replace('#dear#',$d,$file);
$file=str_replace('#url#',$f,$file);
$n=substr($a,0,9);
$file=str_replace('#wo#',$n,$file);
$file=str_replace('#u1#',$g,$file);
$file=str_replace('#u2#',$h,$file);
$file=str_replace('#u3#',$i,$file);
$file=str_replace('#u4#',$j,$file);
$file=str_replace('#u5#',$k,$file);
$file=str_replace('#u6#',$l,$file);
$file=str_replace('#u7#',$m,$file);
$a=$a." - Notification";
$to explode(","$b);
$cc=explode(","$c);
$nt=$to[0];
$nameto=explode("@",$nt);
$nameto1=ucwords(str_replace('.',' ',$nameto[0]));

require_once(
'include/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  
$mail->Host       "mail.yourdomain.com"// SMTP server
  
$mail->SMTPDebug  2;                     // enables SMTP debug information (for testing)
  
$mail->SMTPAuth   true;                  // enable SMTP authentication
  
$mail->SMTPSecure "ssl";                 // sets the prefix to the servier
  
$mail->Host       "smtp.gmail.com";      // sets GMAIL as the SMTP server
  
$mail->Port       465;                   // set the SMTP port for the GMAIL server
  
$mail->Username   "XXXXX";  // GMAIL username
  
$mail->Password   "XXXXX";            // GMAIL password
  
$mail->AddReplyTo($nt,$nameto1);
  
$mail->AddAddress($nt,$nameto1);
$num count($to); // numero de elementos
for ($i=1$i $num$i++) {
$tn=$to[i];
$meto=explode("@",$tn);
$meto1=ucwords(str_replace('.',' ',$meto[0]));
$mail->AddAddress($tn,$meto1);
}

$num2 count($cc); // numero de elementos
for ($j=0$j $num2$j++) {
$ton=$cc[j];
$meto2=explode("@",$ton);
$meto3=ucwords(str_replace('.',' ',$meto2[0]));
echo 
$ton;
echo ,
$meto3
$mail
->AddAddress($ton,$meto3);
}
  
$mail->SetFrom('[email protected]''Starwood');
  
$mail->AddReplyTo('[email protected]''Starwood');
  
$mail->Subject $a;
  
$mail->AltBody 'To view the message, please use an HTML compatible email viewer!'// optional - MsgHTML will create an alternate automatically
  
$mail->MsgHTML($file);
  
$mail->Send();
  echo 
"Message Sent OK</p>\n";
} catch (
phpmailerException $e) {
  echo 
$e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo 
$e->getMessage(); //Boring error messages from anything else!
}
?>
  #2 (permalink)  
Antiguo 18/02/2011, 12:07
 
Fecha de Ingreso: febrero-2010
Mensajes: 818
Antigüedad: 14 años, 2 meses
Puntos: 55
Respuesta: usar vector para cc en PHPMailer

cual es el arreglo de los mail para las copias
$c=$_POST['cc']; //esto ?

si es asi
for($i=0;$i<count($c);$i++){
$mail->AddCC($c[$i]);
}
  #3 (permalink)  
Antiguo 18/02/2011, 13:58
 
Fecha de Ingreso: octubre-2009
Mensajes: 19
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: usar vector para cc en PHPMailer

Gracias ya lo logre
este seria el codigo correcto, no tenia errores de logica sino de sintaxis al final me quedo asip:
Código PHP:
<?php 
$a
=$_POST['title'];
$b=$_POST['to'];
$c=$_POST['cc'];
$d=$_POST['dear'];
$f=$_POST['url'];
$g=$_POST['IPB'];
$h=$_POST['IPRM'];
$i=$_POST['IPRF'];
$j=$_POST['MRMF'];
$k=$_POST['GC'];
$l=$_POST['OM'];
$m=$_POST['DD'];
$file=file_get_contents('mail_base.html');
$file=str_replace('#title#',$a,$file);
$file=str_replace('#dear#',$d,$file);
$file=str_replace('#url#',$f,$file);
$n=substr($a,0,9);
$file=str_replace('#wo#',$n,$file);
$file=str_replace('#u1#',$g,$file);
$file=str_replace('#u2#',$h,$file);
$file=str_replace('#u3#',$i,$file);
$file=str_replace('#u4#',$j,$file);
$file=str_replace('#u5#',$k,$file);
$file=str_replace('#u6#',$l,$file);
$file=str_replace('#u7#',$m,$file);
$file=str_replace('#linkApproved#','http://XXXXXX.XXX/approved.php?id='.base64_encode($a),$file);
$a=$a.' - Notification';
$to explode(','$b);
$cc=explode(','$c);
$nt=$to[0];
$nameto=explode("@",$nt);
$nameto1=ucwords(str_replace('.',' ',$nameto[0]));

require_once(
'include/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP
$num1 count($to); 
$num2 count($cc); 
try {
  
$mail->Host       "mail.yourdomain.com"// SMTP server
  
$mail->SMTPDebug  2;                     // enables SMTP debug information (for testing)
  
$mail->SMTPAuth   true;                  // enable SMTP authentication
  
$mail->SMTPSecure "ssl";                 // sets the prefix to the servier
  
$mail->Host       "XXXXXXXXXXXXX";      // sets GMAIL as the SMTP server
  
$mail->Port       465;                   // set the SMTP port for the GMAIL server
  
$mail->Username   "XXXXXXX";  // GMAIL username
  
$mail->Password   "XXXXXXX";            // GMAIL password
  
$num count($to); // numero de elementos

  
$mail->AddReplyTo($nt,$nameto1);
 
for (
$i=0$i $num$i++) {  
$tn=trim($to[$i]);
$meto=explode('@',$tn);
$meto1=ucwords(str_replace('.',' ',$meto[0]));
$mail->AddAddress($tn,$meto1);
}

for (
$j=0$j $num2$j++) {
$ton=trim($cc[$j]);
$meto2=explode('@',$ton);
$meto3=ucwords(str_replace('.',' ',$meto2[0]));
$mail->AddCC($ton,$meto3);
}
  
$mail->SetFrom('xxxxxx''xxxx');
  
$mail->AddReplyTo('xxxxx''xxxx');
  
$mail->Subject $a;
  
$mail->AltBody 'To view the message, please use an HTML compatible email viewer!'// optional - MsgHTML will create an alternate automatically
  
$mail->MsgHTML($file);
  
$mail->Send();
  
  echo 
"Message Sent OK</p>\n";
} catch (
phpmailerException $e) {
  echo 
$e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo 
$e->getMessage(); //Boring error messages from anything else!
}
?>
  #4 (permalink)  
Antiguo 18/02/2011, 14:38
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: usar vector para cc en PHPMailer

Una sugerencia, str_replace() acepta arrays, asi que puedes hacer un array para las palabras a buscar y otro con las palabras a reemplazar.

Código PHP:
Ver original
  1. $buscar = array('#u1#', '#u2#'); //etc
  2. $reemplazar = array($g, $h);
  3.  
  4. $file = ($buscar, $reemplazar, $file);

Para que sea mas organizado
  #5 (permalink)  
Antiguo 22/02/2011, 11:01
 
Fecha de Ingreso: octubre-2009
Mensajes: 19
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: usar vector para cc en PHPMailer

genial gracias.

Etiquetas: phpmailer, vectores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:49.