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!
$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
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
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
<?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";
?>
<?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";
?>
<?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
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
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:
<?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";
?>
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 =/
<?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";
?>
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
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.