require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer();
$body = file_get_contents('index.php');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
//$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "mail#gmail.com"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->SetFrom('mail#gmail.com', 'First Last');
$mail->AddReplyTo("mail#gmail.pl","First Last");
$mail->Subject = "New Event";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
if ($_FILES['Photo']['error'] == UPLOAD_ERR_OK)
{
$address = "mail#gmail.com";
$mail->AddAttachment($_FILES['Photo']['tmp_name'], $_FILES['Photo']['name']);
$mail->AddEmbeddedImage($_FILES['Photo']['tmp_name'], $_FILES['Photo']['name']);
$mail->AddAddress($address, "John Doe");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
}
I think already tried everything. Still don't attach files to mail. Any idea?
Trying to attach photos of size less than 3mb. Already tried attach text, images, audio.
I'm using upload form for this.
E:
<form enctype="multipart/form-data" id="new_event" action="event.php" method="post" name="new_event">
<p><label for="Photo">Photo </label><input type="hidden" name="MAX_FILE_SIZE" value="30000" /><input type="file" name="Photo" value="Sarch" /></p>
<input type="submit" name="next1" value="Add Event" />
</form>
Sending email without attachment.
SOLVED
Change name="MAX_FILE_SIZE" value="30000" -> name="MAX_FILE_SIZE" value=""
Related
There is a really old blog entry from Twilio about testing the TTS in browser:
https://www.twilio.com/blog/2011/08/testing-twilios-text-to-speech-engine-using-twilio-client.html
Unfortunately it doesn't contain enough information to put a test together. It also contains a number of dead links and mentions a Github project that I can't find.
I'd really like for users to have the ability to hear what their announcement will sound like prior to firing off the form and starting the phone calls.
I use Lasso (which fires off CURL requests to the Twilio REST API), but any kind of tutorials or hints would be appreciated.
If you set up a demo account on Twilio and use Glitch online php tester (https://glitch.com/edit/#!/php-poc) or a local environment you can create a workable example like I did. You will need to fill in the empty strings to correspond to your app name. Search for TwiML in the website to get to the right section to set the right url of your server that TWilio will call upon request to read content (xml). In my case url was http://<server>/?incoming-call.php tested on Glitch.
You need to grab the Twilio PHP SDK and include the Services/Twilio/Capability.php from https://github.com/twilio/starter-php in your server code.
<?php
require __DIR__ . '/../vendor/autoload.php';
$url = [];
$url = explode('?', $_SERVER['REQUEST_URI']);
if (count($url) == 2 && $url[1] == 'incoming-call.php')
{
header('Content-type: text/xml');
$response = new Twilio\Twiml;
$dialogue = trim($_REQUEST['dialogue']);
$voice = (int) $_REQUEST['voice'];
if (strlen($dialogue) == 0)
{
$dialogue = 'Please enter some text to be spoken.';
}
if ($voice == 1)
{
$gender = 'man';
}
else
{
$gender = 'woman';
}
$response->say($dialogue);
echo $response;
exit;
}
require_once('Services/Twilio/Capability.php');
$accountsid = ''; // YOUR TWILIO ACCOUNT SID
$authtoken = ''; // YOUR TWILIO AUTH TOKEN
$fromNumber = ''; // PHONE NUMBER CALLS WILL COME FROM
$APP_SID = '';
$token = new Services_Twilio_Capability($accountsid, $authtoken);
$token->allowClientOutgoing($APP_SID);
?>
<html>
<head>
<title>Text-To-Speech</title>
<script type="text/javascript" src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.5/twilio.js"></script>
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token->generateToken();?>",{"debug":true});
$(document).ready(function() {
$("#submit").click(function() {
speak();
});
});
function speak() {
var dialogue = $("#dialogue").val();
var voice =
$('input:radio[name=voice]:checked').val();
Twilio.Device.connect({ 'dialogue' :
dialogue, 'voice' : voice });
}
</script>
</head>
<body>
<p>
<label for="dialogue">Text to be spoken</label>
<input type="text" id="dialogue" name="dialogue"
size="50">
</p>
<p>
<label for="voice-male">Male Voice</label>
<input type="radio" id="voice-male" name="voice"
value="1" checked="checked">
<label for="voice-female">Female Voice</label>
<input type="radio" id="voice-female" name="voice"
value="2">
</p>
<p>
<input type="button" id="submit" name="submit"
value="Speak to me">
</p>
</body>
</html>
I have a payment form as follows
<body>
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<div class="content">
<h1>Secure Checkout</h1>
<g:form name="paymentForm"
method="POST"
action="processAcceptPayment" >
<input type="text" name="cardNumber" id="cardNumber" placeholder="cardNumber"/> <br><br>
<input type="text" name="expMonth" id="expMonth" placeholder="expMonth"/> <br><br>
<input type="text" name="expYear" id="expYear" placeholder="expYear"/> <br><br>
<input type="text" name="cardCode" id="cardCode" placeholder="cardCode"/> <br><br>
<input type="hidden" name="dataValue" id="dataValue" />
<input type="hidden" name="dataDescriptor" id="dataDescriptor" />
<button type="button" onclick="sendPaymentDataToAnet()">Pay</button>
</g:form>
</div>
<g:javascript>
function sendPaymentDataToAnet() {
var authData = {};
authData.clientKey = "valid key";
authData.apiLoginID = "valid id";
var cardData = {};
cardData.cardNumber = document.getElementById("cardNumber").value;
cardData.month = document.getElementById("expMonth").value;
cardData.year = document.getElementById("expYear").value;
cardData.cardCode = document.getElementById("cardCode").value;
var secureData = {};
secureData.authData = authData;
secureData.cardData = cardData;
// If using banking information instead of card information,
// send the bankData object instead of the cardData object.
//
// secureData.bankData = bankData;
Accept.dispatchData(secureData, responseHandler);
}
function responseHandler(response) {
if (response.messages.resultCode === "Error") {
var i = 0;
while (i < response.messages.message.length) {
console.log(
response.messages.message[i].code + ": " +
response.messages.message[i].text
);
i = i + 1;
}
} else {
paymentFormUpdate(response.opaqueData);
}
}
function paymentFormUpdate(opaqueData) {
document.getElementById("dataDescriptor").value = opaqueData.dataDescriptor;
document.getElementById("dataValue").value = opaqueData.dataValue;
document.getElementById("cardNumber").value = "";
document.getElementById("expMonth").value = "";
document.getElementById("expYear").value = "";
document.getElementById("cardCode").value = "";
document.getElementById("accountNumber").value = "";
document.getElementById("routingNumber").value = "";
document.getElementById("nameOnAccount").value = "";
document.getElementById("accountType").value = "";
document.getElementById("paymentForm").submit();
}
</g:javascript>
</body>
This generates the form as follows
I enter test credit card numbers and click Pay.
I get the following error in my javascript console.
I was just following the accept.js tutorial from the official page.
https://developer.authorize.net/api/reference/features/acceptjs.html
I appreciate any help as to the reason for this "Encryption Failed" error? Thanks!
UPDATE:
Ok so i did some more debugging. I put a test code "console.log("test");" inside responseHandler() function and noticed that it was called twice. I am now wondering why is responseHandler() being called twice.
When Accept.js triggers the callback function twice due to some other Javascript error occurring on the page, you can pretty quickly track down the source of that error on the by wrapping the contents of your callback function in a try/catch block:
Accept.dispatchData(secureData, responseHandler);
...
function responseHandler(response) {
try {
if (response.messages.resultCode === "Error") {
var i = 0;
while (i < response.messages.message.length) {
console.log(
response.messages.message[i].code + ": " +
response.messages.message[i].text
);
i = i + 1;
}
}
} catch (error) {
console.log(error);
}
}
Ok so i did some more debugging. I put a test code "console.log("test");" inside responseHandler() function and noticed that it was called twice. I am now wondering why is responseHandler() being called twice.
I repeated this test and can confirm that this is a common cause of this error. It is also true that Accept.js will mistakingly call your responseHandler() twice if it calls a function that has a Javascript error in it, or some other Javascript error is in the page. In my case, I had a sendOrder() AJAX function that was assuming a variable. Once I fixed that other function, the responseHandler() function was called only once.
The same error appeared to me too. Instead seeing the console, I go to the Network tab of Chrome browser and then see the success message has already appeared as below:
opaqueData
:
{dataDescriptor: "COMMON.ACCEPT.INAPP.PAYMENT",…}
Please note, while testing, enter the test cards for sandbox from https://developer.authorize.net/hello_world/testing_guide/
Can any one help me to integrate a form with PHPMailer. I have following form.
<form method="POST">
<p>Name:<input type="text" name="name" size="30"></p>
<p>Email Address:<input type="text" name="email" size="30"></p>
<input type="submit" name="submit" value="Submit">
</form>
I just need to display POST variables in my receiving email's body. I have search and refer alot and spend hours in it, everyone clarifies it with high level explanation. As i am not a programmer can anyone explain me how can i do this with simple explanation. I just done a method as follows but it did'nt work.
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "
<html>
<h2><b>".$name." ".$email."</b></h2>
</html>";
When i tried the above method i am getting error in this line '$name = $_POST['name'];'. The error message is: Notice: Undefined index:' I think i am wrong with my placing order of codes.
Thanks in advance!
<?php
if(array_key_exists("name",$_POST) && $_POST["name"] != "" && array_key_exists("email",$_POST) && $_POST["email"] != ""){
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mail#gmail.com', 'Manager');
$mail->addAddress('mail#gmail.com', 'Administrator'); // Add a recipient
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "<h2><b>".$name." ".$email."</b></h2>";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST">
<p>Name:<input type="text" name="name" size="30" required></p>
<p>Email Address:<input type="email" name="email" size="30" required></p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
}
?>
I have each user's image in my project directory like user1.jpeg, user2.jpeg and so on. But when I try to change a user image it is throughing a error. I am not understanding what to do. Here is the error as follows >>>
Cannot cast object 'org.apache.catalina.core.ApplicationHttpRequest#21740230' with class 'org.apache.catalina.core.ApplicationHttpRequest' to class 'org.springframework.web.multipart.MultipartHttpServletRequest'
And here is my update action >>>
def updateUser = {
String message = ""
MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;
CommonsMultipartFile f = (CommonsMultipartFile) mpr.getFile("userPhoto")//getFile("userPhoto");
if(!f.empty) {
def user = User.get(1)
user.avatarType = f.getContentType()
if(user.save()){
def userId = user.id
String username = user.username
println(userId)
String fileName = username + "." + f.getContentType().substring(6)
new File( grailsApplication.config.images.location.toString() ).mkdirs()
f.transferTo( new File( grailsApplication.config.images.location.toString() + File.separatorChar + fileName) )
message = "Here is your updated Information >>> "
render(view: 'userInfo', model: [message: message],)
}else{
message = "Can not Update User !!!"
render(view: 'editUser', model:[message: message])
return;
}
}else {
flash.message = 'file cannot be empty'
}
}
Can anyone please help me on this please? I am using grails 2.1.0.
EDIT ::
and here is the view for edit user >>>
<div class="main">
<g:form controller="user" action="updateUser">
User Name : ${username} <br/>
Photo : <input type="file" name="userPhoto" /> <p></p>
<g:hiddenField name="userId" id="userId" value="${userId}"/>
<g:submitButton name="updateUser" value="Update" />
</g:form>
// MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;
def f = request.getFile("userPhoto")//getFile("userPhoto");
I have to use <g:uploadForm /> see http://grails.org/doc/latest/guide/theWebLayer.html#uploadingFiles
Everything is fine in your code just add enctype="multipart/form-data" in the form tag, like
<g:form controller="user" action="updateUser" enctype="multipart/form-data">
...
</g:form>
and your code works.
does anybody know how i get phpmailer to work on an uploaded website.
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$body = "You have been added to the University of Portsmouth project
database. Your password is
'".$_POST['Password']."'
And your username is
'".$_POST['Username']."'
please click the link below, login to the website, select account settings and change
the password to become verified";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tsl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 25; // set the SMTP port
$mail->Username = "projectnateabiola#gmail.com"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->From = "projectnateabiola#gmail.com";
$mail->FromName = "Nathan Abiola";
$mail->Subject = "You have been added to the project database, this email is important";
$mail->AltBody = "Please click"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("projectnateabiola#gmail.com","Webmaster");
$mail->AddAddress($_POST['Email'],"First Last");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
The code works when offline, but once i upload it i get the following error when i submit it. Am i missing something like you cant use phpmailer online. Does any body have any potential alternatives. Thanks for any possible help.
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
I use this for my sites. It is a form on a webpage that calls a php file to send an email. I have found that it has issues sometimes on College servers so keep that in mind.
create a file called mailto.php and paste this in (note that you need to put the correct email address in)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Submitted!</title>
</head>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "PUT YOUR EMAIL ADDRESS HERE", "Subject: $subject",
$message, "From: $email" );
echo "Your message has been sent successfully!";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
Then put this in the body of your html file
<form name="formcheck" onsubmit="return formCheck(this);" action="mailto.php" method="post">
<br />
E-mail: <input type="text" name="email" id="email" size="42" />
<br />
<br />
<br/>
Subject: <input type="text" name="subject" id="subject" size="42" />
<br />
<br />
<br />
Message:
<br />
<textarea rows="5" cols="40" name="message" id="message"></textarea>
<br />
<br />
<input type="submit" onClick="return checkmail(this.form.email)" value="Submit" /><input type="reset" />
</form>
Hope this helps and if anyone has suggestions on how to make this better let me know :)