I am new in swiftmailer, I am having this kind of error;
Fatal error: Cannot redeclare class Swift_Mime_Headers_DateHeader in /home/hosting/public_html/lib/classes/Swift/Mime/Headers/DateHeader.php on line 17
I don't know what to do, please help
My code is this:
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
Related
I try to send emails via Swift-Mailer. According to the documentation, it should work like this, but I neither get a mail nor an error message.
Here is the code of the PHP Swift file:
<?php
require_once '/composer/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
->setUsername('*******#gmail.com')
->setPassword('password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['john#doe.com' => 'John Doe'])
->setTo(['infinity.community.work#gmail.com', 'other#domain.org' => 'A name'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
And here is the composer.json:
{
"require": {
"swiftmailer/swiftmailer": "^6.0"
}
}
Check again with this syntax and make sure the email or the password are spelt correctly:
$trp = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('*********#gmail.com')
->setPassword('password');
$mailer = Swift_Mailer::newInstance($trp);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(['john#doe.com' => 'John Doe'])
->setTo(['infinity.community.work#gmail.com', 'other#domain.org' => 'A name'])
->setBody('Here is the message itself');
$mailer->send($message);
EDIT: worked successfully with SwiftMailer version 5.4
I have used this swiftmailer
The PHP code seems to work but ultimately this does nothing.
I hope someone dealt with this repo could help me.
<?php
require_once 'swiftmailer/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465))
->setEncryption('ssl')
->setUsername('alice#wonderland')
->setPassword("zxcfA!0987")
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['john#doe.com' => 'John Doe'])
->setTo(['bob#cling.com' => 'Bob'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
It keeps failing as per my below check and die. Any reason why? The SMTP settings are correct...
require_once '../lib/swift_required.php';
// Create the Transport the call setUsername() and setPassword()
$transport = Swift_SmtpTransport::newInstance('smtp.server.com', 25)
->setUsername('email#server.com')
->setPassword('password')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Creating a test message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$numSent = $mailer->send($message);
if ($mailer->send($message))
{
die('Mail sent');
} else {
die('Error: Mail failed');
}
I need to send mail through localhost (in both LAMP and WAMP) using PHP. How can I do this? I read many tutorials on this requirement and yet didn't get any solutions. I read that using SMTP we can do this but how will I get the credentials for using SMTP? Hope that someone will help me to do this.
Thank you in advance.
There are many ways to send mail in PHP.
You can use PHPs mail function.
http://php.net/manual/en/function.mail.php
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
SwiftMailer is also worth looking at
It has lots of features for sending mail in different ways (transport types, attachments etc), and it's easy to use.
http://swiftmailer.org/
http://swiftmailer.org/docs/sending.html
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password')
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
I have the following code:
<?php
include 'swiftmailer/lib/swift_required.php';
//*** Create the Transport ***
$transport = Swift_SmtpTransport::newInstance('smtp.My-Hosting', 25)
->setUsername('MyUserName')
->setPassword('Password');
//*** Create the Mailer using your created Transport ***
$mailer = Swift_Mailer::newInstance($transport);
//*** Create a message ***
$message = Swift_Message::newInstance('NameOfInstance')
->setFrom(array('Support#test.com' => 'John Doe'))
->setTo(array("John#test.com" => "John Smith"))
->setBody('This is a test email message') ;
//*** Send the message ***
$result = $mailer->send($message);
?>
How do I use a PHP variable (i.e. $email, $name, etc.) in the setFrom, setTo, and setBody arrays? (I do not want to type individual emails/names).
Provided I understand your question and code (as it's unformatted), you should be able to simply replace the strings with the variable name of your choice.
For example, your original code, formatted, is:
setUsername('MyUserName') ->setPassword('Password');
//*** Create the Mailer using your created Transport ***
$mailer = Swift_Mailer::newInstance($transport);
//*** Create a message ***
$message = Swift_Message::newInstance('NameOfInstance') ->setFrom(array('Support#test.com' => 'John Doe')) ->setTo(array("John#test.com" => "John Smith")) ->setBody('This is a test email message') ;
//*** Send the message ***
$result = $mailer->send($message);
Now, you can simply replace the "John#test.com" with $from_email or whatever variable name you choose ... and so forth with the other strings of text.
setUsername('MyUserName')->setPassword('Password');
//*** Create the Mailer using your created Transport ***
$mailer = Swift_Mailer::newInstance($transport);
//*** Create a message ***
$message = Swift_Message::newInstance('NameOfInstance')->
setFrom(array($from_email => $from_name))->
setTo(array($to_email => $to_name))->setBody($body) ;
//*** Send the message ***
$result = $mailer->send($message);