guarana1 Posted April 11, 2014 Report Share Posted April 11, 2014 (edited) Boas, tenho problemas com a classe, não estou a conseguir enviar o email. O meu objetivo é criar uma coisa tipo "newsletter", tenho uma lista de emails na BD. Penso que me safava com um ciclo FOREACH. Mas antes disso tenho de conseguir enviar emails pelo menos para um, neh? 😄 <?php require("class/phpmailer/class.phpmailer.php"); $mail->SetLanguage("en", 'class/phpMailer/language/'); $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->From = "vttsokalo@gmail.com"; $mail->AddAddress("vttsokalo@gmail.com"); $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?> <?php //////////////////////////////////////////////////// // PHPMailer - PHP email class // // Class for sending email using either // sendmail, PHP mail(), or SMTP. Methods are // based upon the standard AspEmail™ classes. // // Copyright © 2001 - 2003 Brent R. Matzelle // // License: LGPL, see LICENSE //////////////////////////////////////////////////// /** * PHPMailer - PHP email transport class * @package PHPMailer * @author Brent R. Matzelle * @copyright 2001 - 2003 Brent R. Matzelle */ class PHPMailer { ///////////////////////////////////////////////// // PUBLIC VARIABLES ///////////////////////////////////////////////// /** * Email priority (1 = High, 3 = Normal, 5 = low). * @var int */ var $Priority = 3; /** * Sets the CharSet of the message. * @var string */ var $CharSet = "iso-8859-1"; /** * Sets the Content-type of the message. * @var string */ var $ContentType = "text/plain"; /** * Sets the Encoding of the message. Options for this are "8bit", * "7bit", "binary", "base64", and "quoted-printable". * @var string */ var $Encoding = "8bit"; /** * Holds the most recent mailer error message. * @var string */ var $ErrorInfo = ""; /** * Sets the From email address for the message. * @var string */ var $From = "info@chapeualto.pt "; /** * Sets the From name of the message. * @var string */ var $FromName = "Taberna ChapéuAlto"; /** * Sets the Sender email (Return-Path) of the message. If not empty, * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. * @var string */ var $Sender = "info@chapeualto.pt "; /** * Sets the Subject of the message. * @var string */ var $Subject = ""; /** * Sets the Body of the message. This can be either an HTML or text body. * If HTML then run IsHTML(true). * @var string */ var $Body = ""; /** * Sets the text-only body of the message. This automatically sets the * email to multipart/alternative. This body can be read by mail * clients that do not have HTML email capability such as mutt. Clients * that can read HTML will view the normal Body. * @var string */ var $AltBody = ""; /** * Sets word wrapping on the body of the message to a given number of * characters. * @var int */ var $WordWrap = 0; /** * Method to send mail: ("mail", "sendmail", or "smtp"). * @var string */ var $Mailer = "smtp"; /** * Sets the path of the sendmail program. * @var string */ var $Sendmail = "/usr/sbin/sendmail"; /** * Path to PHPMailer plugins. This is now only useful if the SMTP class * is in a different directory than the PHP include path. * @var string */ var $PluginDir = ""; /** * Holds PHPMailer version. * @var string */ var $Version = "ChapeuAlto Plugin 1.73"; /** * Sets the email address that a reading confirmation will be sent. * @var string */ var $ConfirmReadingTo = ""; /** * Sets the hostname to use in Message-Id and Received headers * and as default HELO string. If empty, the value returned * by SERVER_NAME is used or 'localhost.localdomain'. * @var string */ var $Hostname = "chapeualto.pt"; ///////////////////////////////////////////////// // SMTP VARIABLES ///////////////////////////////////////////////// /** * Sets the SMTP hosts. All hosts must be separated by a * semicolon. You can also specify a different port * for each host by using this format: [hostname:port] * (e.g. "smtp1.example.com:25;smtp2.example.com"). * Hosts will be tried in order. * @var string */ var $Host = "****.net"; /** * Sets the default SMTP server port. * @var int */ var $Port = 25; /** * Sets the SMTP HELO of the message (Default is $Hostname). * @var string */ var $Helo = ""; /** * Sets SMTP authentication. Utilizes the Username and Password variables. * @var bool */ var $SMTPAuth = true; /** * Sets SMTP username. * @var string */ var $Username = "info@chapeualto.pt "; /** * Sets SMTP password. * @var string */ var $Password = "****; /** * Sets the SMTP server timeout in seconds. This function will not * work with the win32 version. * @var int */ var $Timeout = 10; /** * Sets SMTP class debugging on or off. * @var bool */ var $SMTPDebug = false; /** * Prevents the SMTP connection from being closed after each mail * sending. If this is set to true then to close the connection * requires an explicit call to SmtpClose(). * @var bool */ var $SMTPKeepAlive = false; /**#@+ * @access private */ var $smtp = NULL; var $to = array(); var $cc = array(); var $bcc = array(); var $ReplyTo = array(); var $attachment = array(); var $CustomHeader = array(); var $message_type = ""; var $boundary = array(); var $language = array(); var $error_count = 0; var $LE = "\n"; /**#@-*/ ///////////////////////////////////////////////// // VARIABLE METHODS ///////////////////////////////////////////////// /** * Sets message type to HTML. * @param bool $bool * @return void */ function IsHTML($bool) { if($bool == true) $this->ContentType = "text/html"; else $this->ContentType = "text/plain"; } /** * Sets Mailer to send message using SMTP. * @return void */ function IsSMTP() { $this->Mailer = "smtp"; } /** * Sets Mailer to send message using PHP mail() function. * @return void */ function IsMail() { $this->Mailer = "mail"; } /** * Sets Mailer to send message using the $Sendmail program. * @return void */ function IsSendmail() { $this->Mailer = "sendmail"; } /** * Sets Mailer to send message using the qmail MTA. * @return void */ function IsQmail() { $this->Sendmail = "/var/qmail/bin/sendmail"; $this->Mailer = "sendmail"; } ///////////////////////////////////////////////// // RECIPIENT METHODS ///////////////////////////////////////////////// /** * Adds a "To" address. * @param string $address * @param string $name * @return void */ function AddAddress($address, $name = "") { $cur = count($this->to); $this->to[$cur][0] = trim($address); $this->to[$cur][1] = $name; } /** * Adds a "Cc" address. Note: this function works * with the SMTP mailer on win32, not with the "mail" * mailer. * @param string $address * @param string $name * @return void */ function AddCC($address, $name = "") { $cur = count($this->cc); $this->cc[$cur][0] = trim($address); $this->cc[$cur][1] = $name; } /** * Adds a "Bcc" address. Note: this function works * with the SMTP mailer on win32, not with the "mail" * mailer. * @param string $address * @param string $name * @return void */ Edited April 11, 2014 by guarana1 Link to comment Share on other sites More sharing options...
I-NOZex Posted April 11, 2014 Report Share Posted April 11, 2014 algum erro retornado? B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net Link to comment Share on other sites More sharing options...
guarana1 Posted April 11, 2014 Author Report Share Posted April 11, 2014 (edited) algum erro retornado? Antes estava a dar um erro de Language, mas resolvi com isto $mail->SetLanguage("en", 'class/phpMailer/language/'); Depois disse não aparece nada e não envia o email. Antes estava a dar um erro de Language, mas resolvi com isto $mail->SetLanguage("en", 'class/phpMailer/language/'); Depois disse não aparece nada e não envia o email. tentei por uns echos, e só aparece o primeiro. <?php echo "teste"; require("class/phpmailer/class.phpmailer.php"); $mail->SetLanguage("en", 'class/phpMailer/language/'); $mail = new PHPMailer(); echo "teste2"; $mail->IsSMTP(); // telling the class to use SMTP echo "teste3"; $mail->From = "vttsokalo@gmail.com"; $mail->AddAddress("vttsokalo@gmail.com"); echo "teste4"; $mail->Subject = "First PHPMailer Message"; $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer."; $mail->WordWrap = 50; if(!$mail->Send()) { echo 'Message was not sent.'; echo 'Mailer error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } echo "teste5"; ?> Edited April 11, 2014 by guarana1 Link to comment Share on other sites More sharing options...
I-NOZex Posted April 11, 2014 Report Share Posted April 11, 2014 (edited) substitui o 2º echo por var_dump($mail); e reporta o que aparece btw, tens configurado os servidores smtp? Edited April 11, 2014 by I-NOZex B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net Link to comment Share on other sites More sharing options...
guarana1 Posted April 12, 2014 Author Report Share Posted April 12, 2014 substitui o 2º echo por var_dump($mail); e reporta o que aparece btw, tens configurado os servidores smtp? Como assim configurado os servidores smtp? 😞 O var_dump não da nada. Link to comment Share on other sites More sharing options...
davidcorreia Posted April 12, 2014 Report Share Posted April 12, 2014 estas a tentar aceder a uma instancia de um object que ainda não foi inicializado switch: require("class/phpmailer/class.phpmailer.php"); $mail->SetLanguage("en", 'class/phpMailer/language/'); $mail = new PHPMailer(); to: require("class/phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->SetLanguage("en", 'class/phpMailer/language/'); Link to comment Share on other sites More sharing options...
guarana1 Posted April 13, 2014 Author Report Share Posted April 13, 2014 (edited) Ok, aparece isto agora. Object(PHPMailer)#1 (39) { ["Priority"]=> int(3) ["CharSet"]=> string(10) "iso-8859-1" ["ContentType"]=> string(10) "text/plain" ["Encoding"]=> string(4) "8bit" ["ErrorInfo"]=> string(28) "Could not load language file" ["From"]=> string(19) "**** " ["FromName"]=> string(19) "*****" ["Sender"]=> string(19) "**** " ["Subject"]=> string(0) "" ["Body"]=> string(0) "" ["AltBody"]=> string(0) "" ["WordWrap"]=> int(0) ["Mailer"]=> string(4) "smtp" ["Sendmail"]=> string(18) "/usr/sbin/sendmail" ["PluginDir"]=> string(0) "" ["Version"]=> string(22) "*** Plugin 1.73" ["ConfirmReadingTo"]=> string(0) "" ["Hostname"]=> string(13) "****" ["Host"]=> string(25) "****" ["Port"]=> int(25) ["Helo"]=> string(0) "" ["SMTPAuth"]=> bool(true) ["Username"]=> string(19) "***** " ["Password"]=> string(9) "****" ["Timeout"]=> int(10) ["SMTPDebug"]=> bool(false) ["SMTPKeepAlive"]=> bool(false) ["smtp"]=> NULL ["to"]=> array(0) { } ["cc"]=> array(0) { } ["bcc"]=> array(0) { } ["ReplyTo"]=> array(0) { } ["attachment"]=> array(0) { } ["CustomHeader"]=> array(0) { } ["message_type"]=> string(0) "" ["boundary"]=> array(0) { } ["language"]=> array(0) { } ["error_count"]=> int(1) ["LE"]=> string(1) " " } teste3teste4Message was not sent.Mailer error: Language string failed to load: recipients_failed****@gmail.comteste5 Edited April 13, 2014 by brunoais code tags para ficar mais legível Link to comment Share on other sites More sharing options...
brunoais Posted April 13, 2014 Report Share Posted April 13, 2014 Já experimentaste procurar na internet pela mensagem de erro? "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
taviroquai Posted April 13, 2014 Report Share Posted April 13, 2014 O I-NOZed já disse... falta a configuração SMTP... servidor? credenciais? portas? 😛 Link to comment Share on other sites More sharing options...
guarana1 Posted April 13, 2014 Author Report Share Posted April 13, 2014 O SMPT já estava configurado. Link to comment Share on other sites More sharing options...
brunoais Posted April 13, 2014 Report Share Posted April 13, 2014 O SMPT já estava configurado. no phpmailer? "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
guarana1 Posted April 13, 2014 Author Report Share Posted April 13, 2014 no phpmailer? Sim, class.smpt.php Já resolvi o problema, a pessoa que me tinha configurado as coisas do email tinha me dito que mudou a password porque continha um $ e estava a dar problmas, então em vez do $ pos um "a". Mas afinal não tinha mudado a password e continuava a estar com o $. Agora os emails vão todos para á caixa de spam, como posso resolver isso? Link to comment Share on other sites More sharing options...
Rui Carlos Posted April 14, 2014 Report Share Posted April 14, 2014 Agora os emails vão todos para á caixa de spam, como posso resolver isso? Vê se isto ajuda. Dependendo da quantidade de emails que tens que enviar, um serviço como o Mandrill também pode ser uma boa opção. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now