Create New Email in PHP

Aspose.Email - Create New Email

To Create new Email using Aspose.Email Java for PHP, simply invoke CreateNewEmail module. Here you can see example code.

PHP Code

 # Create a new instance of MailMessage class

$message = new MailMessage();

\# Set subject of the message

$message->setSubject("New message created by Aspose.Email for Java");

$mail_address = new MailAddress();

\# Set Html body

$message->setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" .

"<font color=blue>This line is in blue color</font>");

\# Set sender information

$message->setFrom(new MailAddress("", "Sender Name", false));

\# Add TO recipients

$message->getTo()->add(new MailAddress("", "Recipient 1", false));

$message->getTo()->add(new MailAddress("", "Recipient 2", false));

\# Add CC recipients

$message->getCC()->add(new MailAddress("", "Recipient 3", false));

$message->getCC()->add(new MailAddress("", "Recipient 4", false));

\# Save message in EML and MSG formats

$mail_message_save_type = new MailMessageSaveType();

$message->save($dataDir . "Message.eml", $mail_message_save_type->getEmlFormat());

$message->save($dataDir . "Message.msg", $mail_message_save_type->getOutlookMessageFormat());

\# Display Status

print "Created email messages Successfully.".PHP_EOL;

Download Running Code

Download Create New Email (Aspose.Email) from any of the below mentioned social coding sites: