Buenas, estoy creando un checkeo automático de pagos IPN de Paypal, la cuestión es que todo funciona a la perfección a excepción del envio de email. El código (de envio, no de todo el script) es el mismo que he usado en otro sitio, por lo que no se que pasa que no se envia.
Código PHP:
<?php
include("../config/config.php");
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$period = '+1 month';
$email = $_POST['payer_email'];
$date = date('d-m-Y');
$subscriptionrecordexists = mysql_query("SELECT * FROM subscriptions WHERE email='$email'");
if (mysql_num_rows($subscriptionrecordexists)){
$subscriptionrecord = mysql_query("SELECT * FROM subscriptions WHERE email='$email'");
$row = mysql_fetch_array($subscriptionrecord);
$currentvalidity = $row['date'];
if (strtotime($currentvalidity) >= strtotime($date)){
$newvalidity = date('d-m-Y', strtotime("$currentvalidity +1 month"));
if(mysql_query("UPDATE subscriptions SET date='$newvalidity' WHERE email='$email'")){
ob_start();
?>
<strong>Thanks you for renew your subscription</strong>
<p>Your account has been extended for one month</p>
<p>-------------------------</p>
<?
$resumen = ob_get_contents();
$maill = "no-reply@".$_SERVER['SERVER_NAME']."";
$email = $_POST['payer_email'];
$destino=mysql_escape_string($email);
$sheader= "From: ".$maill."\r\n";
$sheader=$sheader."X-Mailer:PHP/".phpversion()."\n";
$sheader=$sheader."Mime-Version: 1.0\n";
$sheader=$sheader."Content-Type: text/html";
$asunto='Renew';
mail($destino,$asunto,$resumen,$sheader);
}
}else{
$newvalidity = date('d-m-Y', strtotime("$date +1 month"));
if(mysql_query("UPDATE subscriptions SET date='$newvalidity' WHERE email='$email'")){
ob_start();
?>
<strong>Thanks you for renew your subscription</strong>
<p>Welcome back!</p>
<p>Your account has been extended for one month</p>
<p>-------------------------</p>
<?
$resumen = ob_get_contents();
$maill = "no-reply@".$_SERVER['SERVER_NAME']."";
$email = $_POST['payer_email'];
$destino=mysql_escape_string($email);
$sheader= "From: ".$maill."\r\n";
$sheader=$sheader."X-Mailer:PHP/".phpversion()."\n";
$sheader=$sheader."Mime-Version: 1.0\n";
$sheader=$sheader."Content-Type: text/html";
$asunto='Renew';
mail($destino,$asunto,$resumen,$sheader);
}
}
}else{
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
$password=randomPassword();
$servidor=md5(time()+mysql_escape_string($email));
$newvalidity = date('d-m-Y', strtotime("$date +1 month"));
mysql_query("INSERT INTO subscriptions (email,date) VALUES('". mysql_escape_string($email) ."','$newvalidity') ") or die(mysql_error());
$subscriptionrecor = mysql_query("SELECT * FROM subscriptions WHERE email='$email'");
$roww = mysql_fetch_array($subscriptionrecor);
mysql_query("INSERT INTO config (servidor,idsubscription) VALUES('$servidor','$roww[id]') ") or die(mysql_error());
if(mysql_query("INSERT INTO users (nombre,apellidos,email,pass,fecha,grupo,firstlogin,level,servidor) VALUES('".mysql_escape_string($_POST['first_name'])."','".mysql_escape_string($_POST['last_name'])."','". mysql_escape_string($email) ."','".md5($password)."','$newvalidity','Admin','1','1','".$servidor."') ")){
ob_start();
?>
<strong>Thanks you for your purchase</strong>
<p>Your account information</p>
<p>-------------------------</p>
<p>Email: <?=mysql_escape_string($email)?></p>
<p>Password: <?=$password?></p>
<p>-------------------------</p>
<?
$resumen = ob_get_contents();
$maill = "no-reply@".$_SERVER['SERVER_NAME']."";
$email = $_POST['payer_email'];
$destino=mysql_escape_string($email);
$sheader= "From: ".$maill."\r\n";
$sheader=$sheader."X-Mailer:PHP/".phpversion()."\n";
$sheader=$sheader."Mime-Version: 1.0\n";
$sheader=$sheader."Content-Type: text/html";
$asunto='Purchase';
mail($destino,$asunto,$resumen,$sheader);
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
}
}
fclose ($fp);
}
?>