problems sending mails

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

problems sending mails

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try echoing out the variables that are saying are invalid so you can see what the app is seeing. Post back.
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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 adminmail@mail.pttitulomensagemmail@mail.pt
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I would say try Swiftmailer. It is super simple to use.
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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 ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Follow the documentation on the site. I mean you can literally get a mailer together in a matter of minutes with it.
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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"; 
?>
:)
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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 =/
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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"; 
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:arrow: Moved to swiftmailer forum.
CarlosB
Forum Newbie
Posts: 10
Joined: Tue Mar 27, 2007 5:16 am

Post 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 ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Post Reply