PHP - Cambiar título del email

 
Vista:
Imágen de perfil de Antonio
Val: 66
Ha aumentado su posición en 4 puestos en PHP (en relación al último mes)
Gráfica de PHP

Cambiar título del email

Publicado por Antonio (39 intervenciones) el 21/11/2016 20:30:37
Hola, buenas. Quisiera un consejo sobre el envío del título de un email. Estoy utilizando este código para enviar los correos a los usuarios que se registran:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
$id = $_POST["id"];
$verificacion = $_POST["verificacion"];
$fecha=$_POST["fecha"];
 
include 'conexion.php';
 
//**************************************** Verificacion 1 ok, 2 no aprobado, 0 espera de verificacion, 4 sin movimientos  ****************************
 
//echo '<script language="javascript">alert("El valor de id es = '.$id.' ");</script>'; 
 
 
if($verificacion==3){
    //$tabla=$mysqli->query("update asistente set verificacion=".$verificacion." where id=".$id);
 
    $tabla=$mysqli->query("select c.idCurso, c.cupo, c.nombreCurso, c.claveCurso from curso c inner join curso_asistente ca
        on c.idCurso=ca.idCurso where ca.idUsuario='".$id."'");
    //checar cupo del grupo!!!
    $cursosLlenos ="";
    $cursosIns ="";
    //agregar asistente al curso!!!
 
    while($row = $tabla->fetch_array()) {
 
        //Versiòn 2: Se calcula la capacidad
        /*$inscritos = $mysqli->query("select verificacion from asistente inner join curso_asistente on curso_asistente.idUsuario = asistente.folio && curso_asistente.idCurso = '".$row[0]."' && asistente.verificacion=3");*/
 
        $inscritos = $mysqli->query("select inscrito from curso_asistente where idCurso = '".$row[0]."' && inscrito=1 ");
 
 
        $NumInscritos = mysqli_num_rows($inscritos);
        $capacidad = $row[1] - $NumInscritos; //cupo menos inscritos
 
        if($capacidad>0){
            $inscribir = $mysqli->query("update curso_asistente set inscrito=1 where (idUsuario='".$id."' && idCurso='".$row[0]."')");
            $cursosIns .= " + ".htmlentities($row[2])."<br>";
        }else{
 
            $cursosLlenos .= " - ".htmlentities($row[2])."<br>";
            //$mysqli->query("delete from curso_asistente where nomCurso='".$row[0]."' and idUsuario='".$id."'");
            /*$mysqli->query("update curso set claveCurso='".$row[3]."_X' where
                claveCurso='".$row[3]."' and year ='".$fecha."'");*/
 
        }
 
    }
 
    $tabla=$mysqli->query("update asistente set verificacion=".$verificacion." where folio='".$id."'");
    $tabla=$mysqli->query("update factura set verificacion=1 where idUsuario='".$id."'");
 
}else if($verificacion==2){ //SI ES RECHAZADO
    $tabla3=$mysqli->query("update asistente set verificacion=".$verificacion." where folio='".$id."'");
    $tabla3=$mysqli->query("update factura set verificacion=0 where idUsuario='".$id."'");
}
 
 
 
    //////////////////Se agrega nuevo codigo para enviar correo electronico de confirmacion
    include "config.php";
    require 'class.phpmailer.php';
    $mail = new PHPMailer();
    //Luego tenemos que iniciar la validaci&oacute;n por SMTP:
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->Host = $host; // SMTP a utilizar. Por ej. smtp.elserver.com
    $mail->Username = $Username; // Correo completo a utilizar
    $mail->Password = $password; // Contrase&ntilde;a
    $mail->Port = $port; // Puerto a utilizar
    $mail->SMTPSecure = $smtpSecure;
    //Con estas pocas l&iacute;neas iniciamos una conexi&oacute;n con el SMTP. Lo que ahora deber&iacute;amos 
    //hacer, es configurar el mensaje a enviar, el //From, etc.
    //$mail->From = "adan.sandez21@live.com.mx"; // Desde donde enviamos (Para mostrar)
    $mail->FromName = $fromName;
    //$tabla=$mysqli->query("Select * from asistente where id='".$id."'");
    $tabla=$mysqli->query("Select * from asistente where folio='".$id."'");
    //Estas dos l&iacute;neas, cumplir&iacute;an la funci&oacute;n de encabezado (En mail() usado de esta forma: “From: Nombre <correo@dominio.com>) de //correo.
 
    while($row = $tabla->fetch_array()){
 
        $mail->AddAddress($row[6]); // Esta es la direcci&oacute;n a donde enviamos //SE cambio row 7 por row 6.
       // $mail->AddBCC("adrianvo@mat.uson.mx", $name = "Adrian Vazquez");  // Esta es la copia oculta que se envia.
        $mail->IsHTML(true); // El correo se env&iacute;a como HTML
        $mail->Subject = "Inscripcion CONFIRMADA a la SNIDM - Universidad de Sonora"; // Este es el titulo del email.
 
        if($verificacion==3){
            $body = "<strong> Hola ".$row[0].",<br><br>
            Este correo es para confirmar que tu inscripci&oacute;n a la Semana Nacional de Investigaci&oacute;n y 
            Docencia en Matem&aacute;ticas ha sido registrada EXITOSAMENTE. </strong><br><br>";
        }else if($verificacion==2 && $row[10]=0 ){ //si es becado
            $body = "<strong> Hola ".$row[0].",<br><br>
            Este correo es para informar que tu inscripci&oacute;n a la Semana Nacional de Investigaci&oacute;n y 
            Docencia en Matem&aacute;ticas NO est&aacute; finalizada. Lamentablemente no se pudo visualizar bien la imagen de tu credencial. Te invitamos a subir de nuevo dicha imagen. </strong><br><br>";
 
        }else if($verificacion==2 && $row[10]=1){//si NO es becado
             $body = "<strong> Hola ".$row[0].",<br><br>
            Este correo es para informar que tu inscripci&oacute;n a la Semana Nacional de Investigaci&oacute;n y 
            Docencia en Matem&aacute;ticas NO st&aacute; COMPLETA. Lamentablemente no se pudo visualizar bien la imagen del comprobante de pago. Te invitamos a subir de nuevo dicha imagen.  </strong><br><br>";
 
        }
 
        $body .= "<span><strong>Cursos Seleccionados:</strong></span><br>";
 
        $cursoSelec = $mysqli->query("select curso.nombreCurso from curso
                            inner join curso_asistente on curso.idCurso = curso_asistente.idCurso
                            where idUsuario='".$id."'"); //Solo los cursos seleccionados.
        /*$tabla = $mysqli->query("select curso.nombreCurso from curso_asistente
                            inner join curso on curso.idCurso = curso_asistente.idCurso
                            where idUsuario='".$id."'");
 
        */
         while($curso=$cursoSelec->fetch_array()){
                $body .= " + ".htmlentities($curso[0])."<br>";
            }
 
        $body .= "<span><strong>Cursos donde obtuvo cupo:</strong></span><br>" .$cursosIns;
        $body .="<span><strong>Cursos donde NO obtuvo cupo:</strong></span><br>" .$cursosLlenos;
            /*if( $tabla->num_rows > 0 ){
                  $tabla = $mysqli->query("select curso.nombreCurso from curso
                            inner join curso_asistente on curso.idCurso = curso_asistente.idCurso
                            where idUsuario='".$id."' && inscrito=1"); //Aqui se consideran las materias en las que fue aceptado.

            while($row=$tabla->fetch_array()){
                $body .= " + ".htmlentities($row[0])."<br>";
            }
            //else{
            //$body .="Desafortunadamente no pudo inscribirse en los siguientes cursos:<br>" .$cursosLlenos;
       //}
        }*/
 
        $body .= "<strong>Datos De registro:</strong><br>";
        $body .= "<strong>Folio</strong>:".$row[5]."<br>";
        $body .= "<strong>Nombre:</strong>".$row[0]." ".$row[1]." ".$row[2]."<br>";
        $body .= "<strong>Registrado como:</strong>".$row[4]."<br>";
        $body .= "<strong>Instituci&oacute;n</strong>:".$row[3]."<br><br>";
 
        if($row[11]=='1'){
            //$body.=    "<strong>Datos de facturaci&oacute;n:</strong><br>";
            $fac=$mysqli->query("Select * from factura where idUsuario='".$id."'");
 
            while($fact = $fac->fetch_array()){
                $body .= "<strong>Datos De Facturaci&oacute;n:</strong><br>";
                $body .= "<strong>Nombre</strong>:".$fact[0]."<br>";
                $body .= "<strong>Calle</strong>:".$fact[1]."<br>";
                $body .= "<strong>N&uacute;mero</strong>:".$fact[2]."<br>";
                $body .= "<strong>Colonia</strong>:".$fact[3]."<br>";
                $body .= "<strong>C.P.</strong>:".$fact[4]."<br>";
                $body .= "<strong>Municipio</strong>:".$fact[5]."<br>";
                $body .= "<strong>Estado</strong>:".$fact[6]."<br>";
                $body .= "<strong>Pa&iacute;s</strong>:".$fact[11]."<br>";
                $body .= "<strong>R.F.C</strong>:".$fact[7]."<br>";
                if($fact[10]==1) $fact[10]="Si";
                else $fact[10]="No";
                $body .= "<strong>Iva desglosado: </strong>".$fact[10]."<br>";//quedo un 1 o un 0. Deberia mandarse un si o un no.
                $body .= "<strong>E-mail</strong>:".$fact[9]."<br><br>";
            }
 
        }
 
        $mail->Body = $body; // Mensaje a enviar
 
        $exito = $mail->Send(); // Env&iacute;a el correo.
 
        //Enviar copia
 
 
        //Tambi&eacute;n podr&iacute;amos agregar simples verificaciones para saber si se envi&oacute;:
        if($exito){
            echo true;
            echo "Se envio";
        }else{
            echo $mail->ErrorInfo;
        }
 
    }
 
$mysqli->close();
header("Location:panelC.php?view=A1&fecha=".$fecha."");
?>

En caso de que "verificación==3" (osea que el asistente sea aceptado), se envía un correo con el título: "Inscripcion CONFIRMADA a la SNIDM - Universidad de Sonora".

Aquí viene mi duda, cuál es la manera más adecuada para que cuando "verificacion==2 && $row[10]=1" (Asistente NO aceptado) Y "verificacion==2 && $row[10]=0" (asistente tampoco aceptado)

Me envíe otro título en el correo, en lugar de "Inscripcion CONFIRMADA" me mande: "Inscripcion DENEGADA". Se tiene que hacer otro correo? o cómo lo puedo hacer?, gracias de antemano !!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Lawliet
Val: 478
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Cambiar título del email

Publicado por Lawliet (351 intervenciones) el 22/11/2016 03:45:01
Hola...

Bueno, supongo que tal vez no es exactamente lo que necesitas pero es un buen ejemplo de como cambiar el asunto de acuerdo a tus validaciones.

index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<html>
	<head>
		<title>Enviar Correo</title>
		<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
	</head>
	<body>
		<form action="../control/correo.php" method="post">
			<table>
				<tr>
					<td>Estatus:</td>
					<td>
						<input type="radio" name="estatus" value="1"> Aceptado
						<input type="radio" name="estatus" value="2"> No Aceptado
						<input type="radio" name="estatus" value="3"> Pendiente
					</td>
				</tr>
				<tr>
					<td>E-mail:</td>
					<td><input type="text" name="correo"/></td>
				</tr>
				<tr>
					<td>Mensaje:</td>
					<td><textarea name="cuerpo"></textarea></td>
				</tr>
				<tr align="center">
					<td colspan="2"><input type="submit" value="Enviar"/></td>
				</tr>
			</table>
		</form>
	</body>
</html>

correo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Guardar los datos recibidos en variables.
$estatus = $_POST['estatus'];
$email 	 = $_POST['correo'];
$mensaje = $_POST['cuerpo'];
$destino = "zhapyro_5@hotmail.com";
$asunto = "";
 
// Armamos el asunto del mensaje de acuerdo al estatus recibido.
switch($estatus){
	case 1 :
		$asunto = "ACEPTADO.";
	break;
	case 2 :
		$asunto = "NO ACEPTADO.";
	break;
	default :
		$asunto = "ASUNTO POR DEFECTO.";
	break;
}
 
// Estas son cabeceras que se usan para evitar que el correo llegue a SPAM.
$headers = "From: $email\r\n";
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
 
// Armamos el cuerpo del mensaje.
$cuerpo = "<strong>Email:</strong> ".$email."<br>";
$cuerpo .= "<strong>Mensaje:</strong> ".$mensaje;
 
// Envio
mail($destino,$asunto,$cuerpo,$headers);

No creo tenga mucho que explicar, lo único importante a resaltar es el switch() que de acuerdo al valor que se recibe en la variable $estatus, asigna el asunto correspondiente según sea el caso.

Sin más que comentar, quedo al pendiente de las dudas y/o comentarios.

Saludos!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Antonio
Val: 66
Ha aumentado su posición en 4 puestos en PHP (en relación al último mes)
Gráfica de PHP

Cambiar título del email

Publicado por Antonio (39 intervenciones) el 22/11/2016 07:22:29
Hola, gracias por contestar !
Lo he podido hacer, encontré un método, de echo, ya lo tenía en mi código, simplemente usando otro "$mail->Subject =" para el otro título y listo.
Saludos !!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar