I’m using Eoghan’s PHP Simple Mail script to send emails. I have an application which has two file fields, one is optional. I need to attach both files, only if both are provided.
The object is formatted strangely though:
$send = $mailer->setTo('eoghan@example.com', 'John Smith')
->setSubject('Test Message')
->setFrom('no-reply@domain.com', 'Domain.com')
->send();
I’m not sure how to break this down into multiple lines. Right now it’s all one big run on object oriented thing that I do not comprehend.
I assume it’s something like this?
$send = $mailer->setTo($_TO_EMAIL, $_TO_NAME)
->setSubject($_SUBJECT)
->setFrom($_FROM_EMAIL, $_FROM_NAME);
// If true, send the mail
if ($my_var) $send .= $mailer->send();
EDIT: Also, what is this sort of behavior / syntax called, so I can learn it?
This is an example of method chaining. Each of the function calls (with the exception of
send()returns a reference to the$mailerobject. It’s functionally equivalent to:To answer your question the last should look like this: