I'm trying to send emails to users from my site just like how craiglist does it.(E.g When user A responds to a post by user B, an email gets sent out to user A informing him that user A has responded to his post.User B can then press the reply button in his email client like gmial/hotmail and the reply email will get sent to user A, and any further correspondence will be strictly between the 2 of them, with my server only sending the initial email.)
Currently i have written a function that sends out an email to the user upon successful registration and i am thinking of modifying it for use in the situation above. However, i am not sure how i would go about doing it as i can't seem to change the FROM field in my function.
Note.I'm still new to programming in general and am currently using PHP, and Swiftmailer to handle my emails.
My function:
function Activation($email,$token){
$transport=Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('test@gmail.com')
->setPassword('testpass');
$mailer=Swift_Mailer::newInstance($transport);
$message=Swift_Message::newInstance()
->setSubject('Account activation')
->setFrom(array('mymail@gmail.com' => '*Website name*'))
->setTo(array($email => $email))
->setBody("
Thank you for registering with us. Before we can activate your account one last step must be taken to complete your registration.
<br />
<br />
Please note - you must complete this last step to become a registered member. You will only need to visit this URL once to activate your account.
<br />
<br />
To complete your registration, please visit this URL:
<a href=http://localhost/test/account/activate.php?code=$token >http://localhost/test/account/activate.php?code=".$token."</a>
<br />
<br />
**** Does The Above URL Not Work? ****
If the above URL does not work, please go to the following link into your browser:
http://localhost/test/account/activate.php
<br />
<br />
Please be sure not to add extra spaces. You will need to type in your email and activation code on the page that appears when you visit the URL.
<br />
<br />
Your email is: ".$email."
<br />
Your Activation code is: ".$token."
<br />
<br />
If you are still having problems signing up please contact a member of our support staff at *contactemail*
<br />
<br />
All the best
","text/html");
if (!$mailer->send($message))
{
throw new Exception('Message sending failed');
}
}
Any help would be greatly appreciated.