php swiftmailer two message instances with one mailer instance?
Note: this is intended to be a Community wiki since it was taken from a deleted answer by yannis; The suggestion to do this was here

Using two message instances is fine as is most of your code. There is one major issue though, you don't validate the email, you just check if the $_POST variable was set and is not empty but you don't check if the email format is &quot;name@domain.tld&quot;. The simplest thing you could do is:
$email = 
    isset($_POST[&quot;email&quot;]) &amp;&amp; !empty($_POST[&quot;email&quot;]) 
    ? filter_var($email, filter_var($_POST[&quot;email&quot;], FILTER_SANITIZE_EMAIL) )
    : &quot;No data&quot;;

The filter extension greatly helps you sanitize and validate variables. It's on by default since PHP 5.2, if you are working on an earlier version, you can substitute it with an email validation regular expression. By the way, if you are unfamiliar with the conditional format I'm using, it's called ternary operator and it goes something like this:
$variable = 
    ( condition )
    ? ( value if condition is true )
    : ( value if condition is false );

When actually sending the email, you should do:
if( $email != &quot;No Data&quot; &amp;&amp; send_email($info) ) {
  header(&quot;Location:/thank-you&quot;);  
} else {
  header(&quot;Location:/error&quot;);
}

That way and since the check $email != &quot;No Data&quot; is first, send_email($info) will never execute for a missing or invalid email. So the 2 instances of a hefty library will never instantiate needlessly.
Lastly, a very minor change, that might be considered a matter of style. Here:
if ($mailer-&gt;send($message) &amp;&amp; $mailer-&gt;send($message2)) 
    return true;
else
    return false;  

You are returning a boolean value based on the boolean return of $mailer-&gt;send($message) &amp;&amp; $mailer-&gt;send($message2). You can simply rewrite as:
return $mailer-&gt;send($message) &amp;&amp; $mailer-&gt;send($message2);