Sending EMAILS with SCRIPTCASE

To send an email with Scriptcase we will use sc_mail_send Macro.

First, I’ve created a Control application with an unique field where we will type the message.

In onValidate Event I am using this code:

$smtp = “smtp.mail.yahoo.com.br”; //smtp address
$usr = “arteiro.netmake”; //User name
$pw = “netmake2009”; //Password
$out = “arteiro.netmake@yahoo.com.br”; //message from
$in = “youremail@xxx.com”; //message to
$sbj = “Sending email using Scriptcase”; //Subject
$msg = {texto}; //body message - {texto} is a field of the form

sc_mail_send ($smtp, $usr, $pw, $out, $in, $sbj, $msg, ‘H’, ‘’, ‘’, ‘587’);

Re: Sending EMAILS with SCRIPTCASE

Tutorials How to send email using Scriptcase.

http://www.scriptcase.net/phpgenerator/samples/tutoriais/programming/mcr06.php

Sending email with attachments

http://www.scriptcase.net/phpgenerator/samples/tutoriais/programming/mcr13.php

Re: Sending EMAILS with SCRIPTCASE

Hi,
While this works fine on my desktop development (Linux/Apache) box, it falls over on my virtual hosting service.

I have reverted to the standard PHP mail() function

sc_error_exit() ;
$msg = {fullname}." requests more information to be emailed to “.{email}.”.Reason: ".{message};
$sbj = "Info Request from Website- Index “.[parm1].”: ".[parm2];
$to = “admin@ourserver.gov.au”;
$headers = “From: noreply@ourserver.gov.au Cc:webmaster@ourserver.net”;

if (mail($to, $sbj, $msg,$headers)) {
sc_alert(“Message successfully sent!”);
} else {
sc_alert(“Message delivery failed…”);
}

Re: Sending EMAILS with SCRIPTCASE

You may also want to have a look at PHPMailer:
http://phpmailer.worxware.com/

I simply copied the download to a directory under my app and called it with include(…) as shown in the examples.

They have plenty of examples and I have tested the SMTP example as working fine a SC5 Control app.
http://phpmailer.worxware.com/index.php?pg=examplebsmtp

Other examples.
http://phpmailer.worxware.com/index.php?pg=examples

Regards,
Scott.

Re: Sending EMAILS with SCRIPTCASE

Thanks, Scott.

It remains that it would be neat if the inbuilt macro was working, though. :frowning:

ON the upside, writing a PHP code snippet isn’t a big deal.

Cheers

Re: Sending EMAILS with SCRIPTCASE

Hi all!
i want to know how can i send an email to a several email address? is this possible?
Thanks in advance!

Re: Sending EMAILS with SCRIPTCASE

Yes, you can use a “foreach”, “for”, “while” or another loop command to get emails from an array and send the emails.

Re: Sending EMAILS with SCRIPTCASE

Hi Vitor,

My Gmail account requires TLS encryption how can I set this up so that I can send emails using the sc_mail macro.
Many thanks.

George

Re: Sending EMAILS with SCRIPTCASE

Hi,
I have set up sc_mail using Vitors settings and it works. However when I set up my gmail account I get the following message:

Uncaught Error of type [Swift_ConnectionException] with message [Authentication failed using username ‘georgeloseby’ and password ‘*********’]

I am using the same username and password in my Outlook settings which is working.
Please can you assist.
Many thanks
Georghe

Re: Sending EMAILS with SCRIPTCASE

I figure this out… I hope someone still needs help on this.
All i had to do is change the port to 465 and add ‘S’ right after the port to make it SSL (Secure)…
Works like a charm. Look at example below…

$smtp = “smtp.gmail.com”; //smtp address
$usr = “enter@yourgmailaddress.com”; //User name
$pw = “enteryourpassword”; //Password
$out = “from@emailaddress.com”; //message from
$in = to@emailaddress.com; //message to
$sbj = “Sending email using Scriptcase”; //Subject
$msg = {texto}; //body message - {texto} is a field of the form

sc_mail_send ($smtp, $usr, $pw, $out, $in, $sbj, $msg, ‘T’, ‘’, ‘’, ‘465’,‘S’);

i have a problem with email header, need help :frowning:

I have a problem with email header, in this sc_mail_send there are no header email, so it make my mail server can not fill the “from” field … i send the picture latter cause i’m still in my office now, so i cant uploading every data. how can u give the solution for the header of the email using sc_mail_send??

Best regard

Yogie
thx

Thank you all for this post, this is exactly what i am looking for… :slight_smile:

Here is example of another method: PHP Script for Sending Email using Gmail SMTP

For sending email using SMTP we need not have entire PHPMailer library. It is sufficient to have only class.phpmailer.php and class.smtp.php of this library.

We should set subject, content and header information. When we send email using Gmail SMTP make sure to set SMTPAuth as TRUE and SMTPSecure as tls/ssl. Use your Gmail Username and Password to send email.

<?php require(‘phpmailer/class.phpmailer.php’);
$mail =newPHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug=0;
$mail->SMTPAuth= TRUE;
$mail->SMTPSecure=“tls”;
$mail->Port=587;
$mail->Username=“your gmail username”;
$mail->Password=“your gmail password”;
$mail->Host=“smtp.gmail.com”;
$mail->Mailer=“smtp”;
$mail->SetFrom(“Your from email”,“from name”);
$mail->AddReplyTo(“from email”,“PHPPot”);
$mail->AddAddress(“recipient email”);
$mail->Subject=“Test email using PHP mailer”;
$mail->WordWrap=80;
$content ="<b>This is a test email using PHP mailer class.</b>";
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send()) echo “Problem sending email.”;
else echo “email sent.”;?>

For setting FromEmail and FromName, we can either use SetFrom()function or use PHPMailer properties PHPMailer::From and PHPMailer::FromName. For example,

$mail->From=“from email address”;
$mail->FromName=“from name”; AddReplyTo(), AddAddress() functions will accept array of email addresses, and name is optional.

If we have HTML content as mail body, we need to set content body text/html by using,

$mail->IsHTML(true);

After setting all properties and mailer information with PHPMailer object, PHPMailer::send() function returns TRUE on successful mail transfer and FALSE on failure.

how to implement it on scriptcase mr ?
i had add phpmailer as external library on sc.8.1
and call in with

sc_include_library(‘prj’, ‘phpmailer’, ‘PHPMailerAutoload.php’,‘true’,‘true’);

and i use script like this

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = ‘html’;
$mail->Host = “smtp.gmail.com”;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = “myemail@gmail.com”;
$mail->Password = “mypass”;
$mail->setFrom(‘myemail@gmail.com’, ‘Admin Sistem HRIS’);
$mail->addAddress([usr_email]);
$mail->Subject = {lang_subject_mail};
$mail->msgHTML($param_message);
if (!$mail->send())
{
sc_alert({lang_mail_sended_ok} );
}
else
{
sc_erro_mensagem({sc_mail_erro});
}

[SIZE=18px]but not work[/SIZE]