Page 1 of 2
problems sending mails
Posted: Thu Mar 29, 2007 3:36 pm
by CarlosB
Hey! I'm having a little problem. I'm trying to send mails via php using XPertMailer, but i can't fix these problems

Can anybody help me? I've put the erros under the php code. Thanks!
Code: Select all
$mailuser=$_GET['mail'];
$titulo=$_GET['titulo'];
$mensagem=$_GET['mensagem'];
//$destinatario=$_GET['destinatario'];
set_time_limit(0);
require_once './XPertMailer.php';
$mail = new XpertMailer();
$mail->from('$mailuser');
$send = $mail->send('$mailuser', '$titulo', '$mensagem');
if($send){
echo "OK, o E-Mail foi enviado para $destinatario, por $mailuser";
}else{
echo "Ocorreu um erro...contate o admin";
}
Warning: Invalid from mail address format on class XPertMailer->from() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 1035
Warning: Invalid to e-mail address format '$mailuser' on class XPertMailer->send() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 706
Warning: Can not find any valid to e-mail address on class XPertMailer->send() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 711
Ocorreu um erro...contate o admin
Posted: Thu Mar 29, 2007 3:37 pm
by RobertGonzalez
Try echoing out the variables that are saying are invalid so you can see what the app is seeing. Post back.
Posted: Thu Mar 29, 2007 3:56 pm
by CarlosB
Everah wrote:Try echoing out the variables that are saying are invalid so you can see what the app is seeing. Post back.
This is the result, what is in bold is the things i wrote int the text boxes:
Warning: Invalid from mail address format on class XPertMailer->from() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 1035
Warning: Invalid to e-mail address format '$mailuser' on class XPertMailer->send() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 706
Warning: Can not find any valid to e-mail address on class XPertMailer->send() in c:\Inetpub\wwwroot\sites\enviar_mail\XPertMailer.php on line 711
Ocorreu um erro...contate o admin
mail@mail.pttitulomensagemmail@mail.pt
Posted: Thu Mar 29, 2007 4:16 pm
by RobertGonzalez
I would say try
Swiftmailer. It is super simple to use.
Posted: Thu Mar 29, 2007 4:58 pm
by CarlosB
thanks for the tip

I've downloaded it, and now i'm trying to figure out how it works (i'm still pretty new at this). Do you know any good tutorial or some pieces of code which I could guide me from? Thanks again for your help

Posted: Thu Mar 29, 2007 5:09 pm
by RobertGonzalez
Follow the documentation on the site. I mean you can literally get a mailer together in a matter of minutes with it.
Posted: Fri Mar 30, 2007 6:46 am
by CarlosB
I'm trying to make this work, but i can't figure out this error:
Fatal error: Call to a member function setUsername() on a non-object in c:\Inetpub\wwwroot\sites\enviar_mail\send.php on line 11
This is my code:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
//Start Swift
$smtp->setUsername("my mail");
$smtp->setPassword("my password");
$conn =& new Swift_Connection_SMTP("my smtp server");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift =& new Swift($conn);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "mail", "mail")) echo "Sent";
else echo "Failed";
?>
Please help me! Thanks
Posted: Fri Mar 30, 2007 6:59 am
by Chris Corbyn
CarlosB wrote:I'm trying to make this work, but i can't figure out this error:
Fatal error: Call to a member function setUsername() on a non-object in c:\Inetpub\wwwroot\sites\enviar_mail\send.php on line 11
This is my code:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
//Start Swift
$smtp->setUsername("my mail");
$smtp->setPassword("my password");
$conn =& new Swift_Connection_SMTP("my smtp server");
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift =& new Swift($conn);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "mail", "mail")) echo "Sent";
else echo "Failed";
?>
Please help me! Thanks
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Authenticator/LOGIN.php";
//Start Swift
$smtp =& new Swift_Connection_SMTP("my smtp server");
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp->setUsername("my mail");
$smtp->setPassword("my password");
$swift =& new Swift($smtp);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "your@address.com", "sender@address.com")) echo "Sent";
else echo "Failed";
?>
Do you know for a fact you need LOGIN authentication? Swift will decide itself if you don't bother attaching an authenticator

Posted: Fri Mar 30, 2007 7:04 am
by CarlosB
If i take out the authentication i get the message "Failed". At least it's not an error =/ Do you have any idea of why it doesn't work? I thought it was because i needed to authenticate, but i guess not =S
Posted: Fri Mar 30, 2007 7:10 am
by Chris Corbyn
CarlosB wrote:If i take out the authentication i get the message "Failed". At least it's not an error =/ Do you have any idea of why it doesn't work? I thought it was because i needed to authenticate, but i guess not =S
No no, I don't mean that, maybe you do need to authenticate. I just mean you call attachAuthenticator() and you only really need to do that if you're a bit of a SMTP expert and know exactly what AUTH method to use. Luckily you chose LOGIN which is the most common, but what I'm basically saying is that you can probably simplify your code to this:
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Start Swift
$smtp =& new Swift_Connection_SMTP("my smtp server");
$smtp->setUsername("my mail");
$smtp->setPassword("my password");
$swift =& new Swift($smtp);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "your@address.com", "sender@address.com")) echo "Sent";
else echo "Failed";
?>

Posted: Fri Mar 30, 2007 8:29 am
by CarlosB
Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'Authentication is not supported by the server but a username and password was given.' in c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift\Connection\SMTP.php:334 Stack trace: #0 c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift\Connection\SMTP.php(334): Swift_Connection_SMTP::runAuthenticators() #1 c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift\Connection\SMTP.php(289): Swift_Connection_SMTP->runAuthenticators(mymail', 'mypassword', Object(Swift)) #2 c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift.php(266): Swift_Connection_SMTP->postConnect(Object(Swift)) #3 c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift.php(224): Swift->handshake(Object(Swift_Events_ResponseEvent)) #4 c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift.php(97): Swift->connect() #5 c:\Inetpub\wwwroot\sites\enviar_mail\send.php(12): Swift->__construct(Object(Swift_Connection_SMTP)) #6 {main} thrown in c:\Inetpub\wwwroot\sites\enviar_mail\lib\Swift\Connection\SMTP.php on line 334
That's what happend when i used that code..i don't really have a clue on how to fix this =/
Posted: Fri Mar 30, 2007 8:31 am
by Chris Corbyn
Well, the error message is pretty descriptive

It says you tried to authenticate against a server that doesn't allow authentication.
Code: Select all
<?php
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Start Swift
$smtp =& new Swift_Connection_SMTP("my smtp server");
$swift =& new Swift($smtp);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "your@address.com", "sender@address.com")) echo "Sent";
else echo "Failed";
?>
Posted: Fri Mar 30, 2007 8:32 am
by Chris Corbyn

Moved to swiftmailer forum.
Posted: Fri Mar 30, 2007 8:43 am
by CarlosB
eheh seems like it worked

at least it didn't give any error message and it appeared "Sent"! Now i'm just waiting to receive the mail. Does it usually take a while? Thanks for everything

Posted: Fri Mar 30, 2007 8:52 am
by Chris Corbyn
CarlosB wrote:eheh seems like it worked

at least it didn't give any error message and it appeared "Sent"! Now i'm just waiting to receive the mail. Does it usually take a while? Thanks for everything

no, it should take as long as SMTP relaying usually takes. If you sent to hotmail then your server needs to have been set up correctly. Also, that message is pretty short. Fill it with lipsum or something for a more realistic send.